--用集合函数
select a2,max(a1) a1,max(a3) a3,max(a4) a4,max(a5) a5 from tablename group by a2

解决方案 »

  1.   

    select a2,min(a1) a1,min(a3) a3,min(a4) a4,min(a5) a5 from tablename group by a2看你取大还是取小:)
      

  2.   

    select identity(int,1,1) as nowid,* into #temp from tablename
    go
    select * from tablename where nowid in 
    (select min(nowid) from tablename group by a2)
      

  3.   

    上面寫錯了
    select identity(int,1,1) as nowid,* into #temp from tablename
    go
    select * from tablename where nowid in 
    (select min(nowid) from #temp group by a2)
      

  4.   

    select * from a aa where not exists (select 1 from a bb where aa.a2=bb.a2 and aa.a1<bb.a1)