表中的数据为:   ID  aa 
    1  1 
    2  1 
    3  1 
    4  2 
    5  2 
    6  3 
    6  3............. 依次类推,我只要aa=1的一条,aa=2的一条,aa=3的一条,依次类推,用TSQL语句应该怎么写,在线等,解决立刻送分 

解决方案 »

  1.   

    select max(ID),aa from tb
    group by aa
      

  2.   

    select max(ID) as ID,aa from tb 
    group by aa
      

  3.   

    select * from 
    tb  t where not exists(select 1 from tb where t.id>id and t.aa=aa)--try
      

  4.   

    select * from 
    tb  t where not exists(select 1 from tb where t.id>id and t.aa=aa)
      

  5.   

      declare @t table( [id] int , aa int )
      insert into @t values( 1,1)
      insert into @t values( 2,1)
      insert into @t values( 3,1)
      insert into @t values( 4,2)
      insert into @t values( 5,2)
      insert into @t values( 6,3)
      insert into @t values( 6,3)
      insert into @t values( 6,5)   
      select aa , min([id]) as [id]  from @t group by aa having Count(*) >=2
      

  6.   

    select max(ID) as ID,aa from tb
    group by aa怎么不对,你测试下不就知道了