码迷,mamicode.com
首页 > 数据库 > 详细

步步为营-89-SQL语句(删除重复数据)

时间:2017-09-15 12:07:22      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:play   语句   span   ide   pen   proc   height   group by   查看   

1:删除重复数据

技术分享

技术分享
--第一步:先找到重复数据
select ProcInstID from record_errorlog
group by ProcInstID
having count(ProcInstID) > 1
--查看一下
select * from record_errorlog 
where ProcInstID in (select ProcInstID from record_errorlog
group by ProcInstID
having count(ProcInstID) > 1);
--第二部 保留ErrorLogID最大的(也就是最新的数据)
delete  from record_errorlog 
where ProcInstID in (select ProcInstID from record_errorlog group by ProcInstID having count(ProcInstID) > 1)
and ErrorLogID not in (select max(ErrorLogID) from  record_errorlog group by ProcInstID having count(ProcInstID )>1);
View Code

 

步步为营-89-SQL语句(删除重复数据)

标签:play   语句   span   ide   pen   proc   height   group by   查看   

原文地址:http://www.cnblogs.com/YK2012/p/7525416.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!