您可以使用ROW_NUMBER解析函数和PARTITION BY主键中除c1之外的所有列,然后按DESC结束顺序使用ORDER BY c1,然后过滤仅返回每个分区中编号最早的行:
SELECT *
FROM (
SELECT t.*,
ROW_NUMBER() OVER (
PARTITION BY c2, c3, c4, c5 -- All the primary key columns except c1
ORDER BY c1 DESC
) AS rn
FROM table_name t
)
WHERE rn = 1;
1条答案
按热度按时间8nuwlpux1#
您可以使用
ROW_NUMBER
解析函数和PARTITION BY
主键中除c1
之外的所有列,然后按DESC
结束顺序使用ORDER BY c1
,然后过滤仅返回每个分区中编号最早的行:字符串