日期:2014-05-17 浏览次数:20498 次
with tb(a,b)as(
select '天津', 1 union all
select '上海', 1 union all
select '北京', 1 union all
select '湖北', 1 union all
select '天津', 2 union all
select '广州', 2 union all
select '湖南', 1 union all
select '北京', 2 union all
select '安徽', 1 union all
select '湖南', 1 union all
select '北京', 3 union all
select '北京', 3 union all
select '北京', 3 union all
select '北京', 3)
, tbb as (
select ROW_NUMBER() over(partition by a,b order by a)number,* from tb
)
delete tbb where number>3
select [key],[user] from (select *,row=row_number()over(partition by [user] order by getdate()) from tb)t where row<4