更新时间:2023-01-30 08:17:41
使用ROW_NUMBER
解析函数找出每组中不是最新的行,然后可以使用在
伪列:DELETE
中关联的 ROWID
Use the ROW_NUMBER
analytic function to find the rows that are not the latest in each group and then you can use the ROWID
pseudo-column to correlate with in the DELETE
:
DELETE FROM tmp_data
WHERE ROWID IN (
SELECT rid
FROM (
SELECT ROWID As rid,
ROW_NUMBER() OVER (
PARTITION BY col_2, col_3, col_6
ORDER BY col_4 DESC
) AS rn
FROM tmp_data
)
WHERE rn > 1
)
删除 22 行.
db<>fiddle 这里