列出A 表中 user id 存在重复的记录(按user id 排序)
SELECT user_id, COUNT(*) AS count
FROM a
GROUP BY user_id
HAVING count > 1
ORDER BY user_id;
删除 A 表中数据重复的记录,保留唯一的 user_id.
此处可以保留唯一的 user_id
DELETE a
FROM a
JOIN (
SELECT user_id, MIN(dept_code) AS min_dept_code
FROM a
GROUP BY user_id
) AS t
ON a.user_id = t.user_id AND a.dept_code != t.min_dept_code;