记录一个分组取前N条数据的SQL:
1 SELECT * 2 FROM ( SELECT ROW_NUMBER() OVER ( PARTITION BY t1.X ORDER BY t1.Y ) AS RNUM , 3 * 4 FROM Table1 t1 5 ) AS T 6 WHERE T.RNUM = N
X:分组的字段;
Y:排序的字段;
N:第N条
记录一个分组取前N条数据的SQL:
1 SELECT * 2 FROM ( SELECT ROW_NUMBER() OVER ( PARTITION BY t1.X ORDER BY t1.Y ) AS RNUM , 3 * 4 FROM Table1 t1 5 ) AS T 6 WHERE T.RNUM = N
X:分组的字段;
Y:排序的字段;
N:第N条