代码语言:javascript复制
-- 查看重复数据
SELECT `item_id`,COUNT(1) FROM app_wine GROUP BY `item_id` HAVING COUNT(1) > 1
代码语言:javascript复制-- 删除重复数据保留一条最新数据
DELETE FROM app_wine WHERE id NOT IN (
SELECT t.min_id FROM (
-- 过滤出重复多余的数据,比如,如果所有记录中存在1条记录是user_name=zhangsan的,那么就取出它;
-- 如果所有记录中存在多条记录是user_name=lisi的,那么只取其中1条,其他的不查询出来
SELECT MIN(id) AS min_id FROM app_wine GROUP BY detail_url
) t
)