SQL Server 分组排序后取第N条数据(或前N条)
节选自 https://blog.csdn.net/cxu123321/article/details/92059001
分组取前N条数据SQL
SELECT * FROM( SELECT ROW_NUMBER() OVER (PARTITION BY t1.X ORDER BY t1.Y) AS RNUM, * FROM Table1 t1 )AS T WHERE T.RNUM = N
X:分组的字段;
Y:排序的字段;
N:第N条