首页 > 其他 > 详细

数据清理——删除多个字段重复的记录

时间:2018-10-08 22:10:07      阅读:178      评论:0      收藏:0      [点我收藏+]

数据库内容,随机编了一些数据,其中认为两个字段Name、Address1一致为重复记录,保留其中一条

技术分享图片

  1. 删除两个字段Name、Address1一致重  复的记录,保留一条:
    • 找出,( 如果没有第三行,会有什么问题呢?可将示例数据中 ID 为4的行,Name字段改为Tom测试一下)
1 select * from tableabc
2 where Name in( select Name from tableabc group by Name, Address1 having count(Name) > 1)
3 and Address1 in( select Address1 from tableabc group by Name, Address1 having count(Address1) > 1)
    • 删除
1 select * from tableabc 
2 where Name in( select Name from tableabc group by Name, Address1 having count(Name) > 1)
3 and Address1 in( select Address1 from tableabc group by Name, Address1 having count(Address1) > 1)
4 and ID not in(select max(ID) from tableabc group by Name,Address1 having count(Name) > 1 )

数据清理——删除多个字段重复的记录

原文:https://www.cnblogs.com/sjqq/p/9757398.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!