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
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