select cuid,aid from (
select cuid, aid,count(1) as num
from register_chn
group by cuid,aid having num > 1
) t;
显示有8条记录,如果手动删除,是很慢且愚蠢的做法,还是用 SQL 执行,镇定之后执行
1234567
delete from register_chn where (cuid,aid) in (
select cuid,aid from (
select cuid, aid,count(1) as num
from register_chn
group by cuid,aid having num > 1
) t
);
影响了8条记录.然后瞬间加上索引.所幸是成功了, 事实上当时的合理操作应该是用事务。
12345678910
BEGIN;
delete from register_chn where (cuid,aid) in (
select cuid,aid from (
select cuid, aid,count(1) as num
from register_chn
group by cuid,aid having num > 1
) t
);
alter table register_chn add unique index(cuid, aid);
COMMINT;