xm,ch
zz,123
zz,345
aa,456
aa,234结果
xm,ch
zz,123
aa,456

解决方案 »

  1.   

    ;with cte as
    (select rn=row_number() over(order by getdate()),* from tb
    )
    select xm,ch from cte t
    where not exists(select 1 from cte where xm=t.xm and rn<t.rn)
      

  2.   

    上面语句放 sqlserver2000 上不行啊
     
      

  3.   


    select rn=identity(int,1,1),* into #tmp from tbselect xm,ch from #tmp t
    where not exists(select 1 from #tmp where xm=t.xm and rn<t.rn)
      

  4.   

    嗯,这正是我想要的,谢谢josy