row_number和partition by分组取top数据,每组查询前N条

--取每个学科的前3条数据

select * from
(
select subject,name,score,ROW_NUMBER() over(PARTITION by subject order by @@identity) as num from #score
) T where T.num <= 3 order by subject

posted @   顿金  阅读(242)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示