按指定字段去重res_id ,executor,保留最早的一条记录ORDER BY id
WITH cte AS (
SELECT
id,
ROW_NUMBER() OVER (
PARTITION BY res_id ,executor
ORDER BY id -- 按ID升序,保留最小ID
) AS rn
FROM plan_task
where year=2026 and state in(0,3,6) and res_type =102007
and delete_state =false
)
update plan_task set delete_state=true ,remark='260119发现有重复的'
WHERE id IN (SELECT id FROM cte WHERE rn > 1);