最近不知道什么情况,用户数据在同一秒内会出现2条甚至多条数据一样的情况,为了避免重复数据插入,需要将重复数据删除后,在添加联合索引。
一,先看一下重复数据总量
SELECT mobile, CONCAT(mobile,UNIX_TIMESTAMP(created_at)) as unit_mobile, count(mobile) as num FROM estimate_user GROUP BY unit_mobile HAVING num > 1;
确认手机号后,把这批手机号数据导出备份,方便后面验证;
二、删除重复数据
DELETE from estimate_user where id not in (select t.max_id from (select max(id) as max_id from users group by CONCAT(mobile,UNIX_TIMESTAMP(created_at)) HAVING num > 1) as t );
三、验证重复手机号是否存在后创建联合索引

标签: none

添加新评论