表结构如下:ID1  ID2
 1    3
 5    8
 1    10
 2    2怎么找出ID1-ID2的差值最大的记录?这里要输出
1  10

解决方案 »

  1.   

    不好意思, 打反了怎么找出ID2-ID1的差值最大的记录?这里要输出
    1  10
      

  2.   

    select *
    from 表
    where id2-id1=(select max(id2-id1) from 表名)
      

  3.   

    create table #t (ID1 int, ID2 int)insert into #t select 1,    3
    insert into #t select  5,    8
    insert into #t select  1,    10
    insert into #t select  2,    2select *
    from #t
    where id2-id1=(select max(id2-id1) from #t)
      
    drop table #t