获取某重复字段重复的第一条记录
示例:
a b c d
1 2 3 4
1 3 4 5
2 2 5 4
3 4 5 4
3 6 5 6
要获取其中第一,三,四条,取出字段a中的重复值
SELECT * FROM
(
select a,b,c,d,ROW_NUMBER() OVER (partition by a order by b DESC,c ASC) AS SX FROM T
group by a,b,c,d
) s
WHERE SX=1
ROW_NUMBER() OVER (partition by a order by b DESC,c ASC)中,partition by 为分组,以a分组,b降序,c升序的格式排序后设置行数
排序后行数类似为 1 2 1 1 2........