鉴于下表:
Sequence Tag ----- ---- 1 a 2 a 3 a 88 a 100 a 1 b 7 b 88 b 101 b
我想要一个查询返回每个标签序列中的第4个(按标签,序列asc排序):
Tag 4thInSequence ----- -------- a 88 b 101
@R_403_323@
WITH Enumerated AS ( SELECT *,ROW_NUMBER() OVER (PARTITION BY Tag ORDER BY Sequence) AS RN FROM MyTable ) SELECT * FROM Enumerated WHERE RN = 4;