mysql查重、去重、更改狀態
阿新 • • 發佈:2020-12-11
1.查重:
select * from file a
where (a.name) in (select name from file WHERE isDelete = 0 and status = 1 GROUP BY phone HAVING count(*)>1);
2.刪除
DELETE a FROM file a, file b
WHERE a.id < b.id AND a.name
= b.name
;
3.修改重複狀態
update file set status =0 where id in(
select * from (
select id from file a
SELECT name FROM file where status =1
GROUP BY name HAVING
count() > 1)
and a.id NOT IN (
SELECT id FROM file
GROUP BY name HAVING count() > 1)) m )