zoukankan      html  css  js  c++  java
  • 数据库清除重复数据

    背景

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

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

    执行步骤

    第一步

    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....)

  • 相关阅读:
    c# 线程同步各类锁
    C#_从DataTable中检索信息
    永无BUG
    标志枚举
    将多行按分隔符"|"合成一行
    回车换行浅析
    url传输编码
    xshell 禁用铃声 提示音
    php 编译安装 mysql.so
    301 302 304
  • 原文地址:https://www.cnblogs.com/snifferhu/p/5675942.html
Copyright © 2011-2022 走看看