SELECT * FROM (
SELECT *, ROW_NUMBER() OVER (PARTITION BY groupByField ORDER BY orderByField DESC) rn FROM t1
) t WHERE rn = 1
SQL SERVER 分组查询并获取每组第一条数据
最新推荐文章于 2023-06-07 11:27:31 发布
SELECT * FROM (
SELECT *, ROW_NUMBER() OVER (PARTITION BY groupByField ORDER BY orderByField DESC) rn FROM t1
) t WHERE rn = 1