您的位置:首页 > 运维架构

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

2012-06-26 17:24 736 查看
--取每个学科的前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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: