列计算查询
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'unionselect 3,'55','700','100' ,'600' union select 4,'42','50','40' ,'48'unionselect 5,'85','80', '80','90'unionselect 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 twhere abs(n2-n1)<10 or ABS(m2-m1)<10/*1 10 20 12 254 42 50 40 485 85 80 80 90*/
[解决办法]
select *,compute=(if (abs(n2-n1)<=10 and ABS(m2-m1)<=10)1else 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 sigfrom t/*ta n1 m1 n2 m2 su1 su2 sig----------- ----------- ----------- ----------- ----------- ----------- ----------- -----------1 10 20 12 25 2 5 12 22 20 50 30 28 10 03 55 700 100 600 45 -100 04 42 50 40 48 -2 -2 15 85 80 80 90 -5 10 06 88 300 50 70 -38 -230 07 90 70 40 80 -50 10 0(7 行受影响)*/