ROW_NUMBER
を使用できます 分析関数を使用し、ROWID
を使用して削除を関連付けます 疑似列:
DELETE FROM my_table
WHERE ROWID IN (
SELECT ROWID
FROM (
SELECT ROW_NUMBER() OVER (
PARTITION BY student_id, subject_id, class_id
ORDER BY expertise_lvl DESC
) AS rn
FROM my_table
)
WHERE rn > 1
)
db <> fiddle こちら