;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)
上面语句放 sqlserver2000 上不行啊
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)
(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)
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)