日期:2014-05-18 浏览次数:20658 次
; WITH tmp AS ( SELECT * , rn = ROW_NUMBER() OVER ( PARTITION BY id ORDER BY nickname ) FROM tb ) SELECT * FROM tmp WHERE rn <= 2
------解决方案--------------------
select * from (select no=row_number() over(partition by id order by addtime desc),* from tb)t where no<3
------解决方案--------------------
select distinct b.* from tb a cross apply (select top 2 * from tb where id=a.id order by addtime desc)b