DELETE
FROM
table
WHERE
(user_id, survey_id) IN (
SELECT
*
FROM
(
SELECT
user_id,
survey_id
FROM
table
GROUP BY
user_id,
survey_id
HAVING
count(*) > 1
) tmp1
)
AND id NOT IN (
SELECT
*
FROM
(
SELECT
max(id)
FROM
table
GROUP BY
user_id,
survey_id
HAVING
count(*) > 1
) tmp2
)
子查询两条一定要用临时表,不然的话会报错