日期:2014-05-18 浏览次数:20449 次
create table t(ta int ,n1 varchar(10),m1 varchar(10), n2 varchar(10),m2 varchar(10)) insert into t select 1,'10','20','12','25' union select 2,'22','20','50','30'union select 3,'55','700','100' ,'600' union select 4,'42','50','40' ,'48'union select 5,'85','80', '80','90'union select 6,'88','300','50','70' union select 7,'90','70', '40','80' select * from t --drop table t -----------按照10为判断值 判断界限的应该是-10<=x<=10 -----------X值为n2-n1,m2-m1的结果 计算结果在上面的范围内 用1表示 否则为0 ---------- 或者换其他的方式思考
select * from t where abs(n2-n1)<10 or ABS(m2-m1)<10 /* 1 10 20 12 25 4 42 50 40 48 5 85 80 80 90 */
------解决方案--------------------
select *,compute=(if (abs(n2-n1)<=10 and ABS(m2-m1)<=10) 1 else 0) from t
------解决方案--------------------
???
select *,n2-n1 as su1,m2-m1 as su2,case when abs(n2-n1)<10 and ABS(m2-m1)<10 then 1 else 0 end as sig from t /* ta n1 m1 n2 m2 su1 su2 sig ----------- ----------- ----------- ----------- ----------- ----------- ----------- ----------- 1 10 20 12 25 2 5 1 2 22 20 50 30 28 10 0 3 55 700 100 600 45 -100 0 4 42 50 40 48 -2 -2 1 5 85 80 80 90 -5 10 0 6 88 300 50 70 -38 -230 0 7 90 70 40 80 -50 10 0 (7 行受影响) */