ZKX's LAB

求助SQL:如何删除重复数据 删除重复数据 sql

2021-04-23知识5

SQL删除重复数据,做软件开发经常会遇到数据库表中存在重复的数据,那么如何删除重复数据呢,下面介绍一种个人使用过的方法。

【sql去除重复数据】 selectDISTINCT finger,width,height,size,typeform imageorder by finger,width,height,size,type

SQL表删除重复数据 删除表中多余的重复记录(多个字段),只留有rowid最小的记录delete from TABLEA awhere(a.A,a.B,a.C,a.D,a.E)in(select A,B,C,D,E from TABLEA group by A,B,C,D,E having count(*)>;1)and rowid not in(select min(rowid)from TABLEA group by A,B,C,D,E having count(*)>;1)and G>;cast('2014-06-01' as datetime).满足的G列跟重复行的关系没描述清楚,不晓得具体什么意思。G的限制,我放最外边了。你可以根据题目意思,挑地方放进去最后日期的限制。分隔线=刚看到追加.做以下补充查询:select*from abcwhere G>;cast('2014-06-01' as datetime)group by A,B,C,D,Ehaving count(*)>;1删除的话,还是参照第一次回答,使用了子查询:delete from abc awhere(a.A,a.B,a.C,a.D,a.E)inselect A,B,C,D,E from abcwhere G>;cast('2014-06-01' as datetime)group by A,B,C,D,E having count(*)>;1and autoid not inselect min(autoid)from abcwhere G>;cast('2014-06-01' as datetime)group by A,B,C,D,Ehaving count(*)>;1以上,你可以参考下,当然,根据具体数据逻辑,还有更简便的写法吧。加油撒~

随机阅读

qrcode
访问手机版