潦草白纸

数据库清除重复数据

背景

历史数据里大量的有重复的电话数据需要删除,无法通过代码连接数据库删除。

注: 懒得废话,直接上过程。

 

执行步骤

第一步

select phone,count(phone) as cnt  from messages group by phone having cnt > 1;

第二步

select id,phone where messages from phone in (第一步.phone,xxx,xxx ...);

第三步

把数据放到excel中

  phone id 函数1 函数2
 x899858339x  3087135  =A1=A2 =IF(C1,"delete from messages where id = "&B1&";","") 
示例 x899858339x  3087135  TRUE  delete from messages where id = 3087135;

把函数2列复制执行就成。

 

 

其实更高效的方式在于

  phone id 函数1 函数2
 x899858339x  3087135  =A1=A2 =IF(C1,B1;","") 
示例 x899858339x  3087135  TRUE  3087135

delete from messages where id in (函数2....)

posted on 2016-07-16 11:50  潦草白纸  阅读(314)  评论(0编辑  收藏  举报

导航