SQL 分组排序查询 ROW_NUMBER() OVER()

1 SELECT
2     [字段1],
3     [字段2],
4     [字段n] 
5 FROM
6     ( SELECT *, ROW_NUMBER ( ) OVER ( PARTITION BY [分组字段1], [分组字段2] ORDER BY [排序字段1] DESC ) AS rn FROM [表名] ) AS A 
7 WHERE
8     A.rn <= 1

 

posted @ 2022-08-29 09:59  Mr_Xul  阅读(17)  评论(0编辑  收藏  举报