表 A
列1  列2  id
12   16    1
13   19    2
0    5     3
25   61    4


选取表A中列2-列1的差值大于5的行

解决方案 »

  1.   

    select MAX(column2-column1) from a
      

  2.   

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

  3.   

    select * from a where col2-col1>5
      

  4.   


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

  5.   


    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,5select * 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
    */