日期:2014-05-17 浏览次数:20722 次
;with t
as(
select px=row_number()over(partition by a,c order by getdate()),* from tb
)
select A,B,C from t where px=1
with tb(A,B,C)
as(
select 1,'*','2' union all
select 1,'$','2' union all
select 2,'Y','F' union all
select 2,'T','F' union all
select 3,'1','R'
)
select a,(select top 1 b.b from tb b where a.a=b.a and a.c=b.c order by newid())b,c from tb a group by a,c
select * from tb a where not exists(select 1 from tb b where a.col1=b.col1 and a.col3=b.col3 and a.col2>b.col2)