爷的眼睛闪亮
insideDotNet En_summerGarden
#####查询重复数据
SELECT t.* FROM  like_user t, (
SELECT user_id, COUNT(user_id), dynamc_id, COUNT(dynamc_id) 
FROM like_user 
GROUP BY user_id, dynamc_id 
HAVING  (COUNT(user_id) > 1) AND  (COUNT(dynamc_id) > 1) 
) a 
WHERE t.user_id=a.user_id AND t.dynamc_id=a.dynamc_id 

#####删除查询到重复的数据,保留最小的id
DELETE FROM like_user WHERE id in (
SELECT b.id  FROM  (  
SELECT t.* FROM like_user  t, (
SELECT user_id, COUNT(user_id), dynamc_id, COUNT(dynamc_id) 
FROM like_user 
GROUP BY user_id, dynamc_id 
HAVING  (COUNT(user_id) > 1) AND  (COUNT(dynamc_id) > 1) 
) a 
WHERE t.user_id=a.user_id AND t.dynamc_id=a.dynamc_id 
) b   WHERE b.id
NOT IN (
SELECT min(id) as id FROM (
SELECT t.* FROM  like_user t, (
SELECT user_id, COUNT(user_id), dynamc_id, COUNT(dynamc_id) 
FROM like_user 
GROUP BY user_id, dynamc_id 
HAVING  (COUNT(user_id) > 1) AND  (COUNT(dynamc_id) > 1) 
) a 
WHERE t.user_id=a.user_id AND t.dynamc_id=a.dynamc_id 
)a  GROUP BY a.user_id,a.dynamc_id
)
)

 

posted on 2022-12-21 11:58  爷的眼睛闪亮  阅读(44)  评论(0编辑  收藏  举报