+ -
当前位置:首页 → 问答吧 → 选择两列差值大于某值的行

选择两列差值大于某值的行

时间:2011-12-27

来源:互联网

表 A
列1 列2 id
12 16 1
13 19 2
0 5 3
25 61 4
。。。
。。。
选取表A中列2-列1的差值大于5的行

作者: losinghappy   发布时间: 2011-12-27

select MAX(column2-column1) from a

作者: zhaowenzhong   发布时间: 2011-12-27

select * from a where (column2-column1)>5

作者: zhaowenzhong   发布时间: 2011-12-27

select * from a where col2-col1>5

作者: fredrickhu   发布时间: 2011-12-27

SQL code

select * from 表A where (列2-列1)>5

作者: pengxuan   发布时间: 2011-12-27

引用 3 楼 fredrickhu 的回复:
select * from a where col2-col1>5

+1

作者: ju523756055   发布时间: 2011-12-27

SQL code

declare @表A table (列1 int,列2 int,id int)
insert into @表A
select 12,16,1 union all
select 13,19,2 union all
select 0,5,3 union all
select 25,61,4 union all
select 20,10,5

select * from @表A where 列2-列1>5
/*
列1          列2          id
----------- ----------- -----------
13          19          2
25          61          4
*/
select * from @表A where abs(列2-列1)>5
/*
列1          列2          id
----------- ----------- -----------
13          19          2
25          61          4
20          10          5
*/

作者: maco_wang   发布时间: 2011-12-27