ZKX's LAB

sql删除表中的重复数据 SQL 删除表中重复的数据

2021-04-27知识12

sql删除两表重复数据 先把唯一值查出来放一个临时表里,再把原表内容删除,最后把临时表里的内容插入到原表里。select distinct(sPointguid),slotname,TypeCode into#a from tempdelete from tempinsert temp select*from#a

求删除SQL数据库中某个表的重复数据 1.先将umane用一个临时表存起来select distinct(uname)uname into#a form users2.删除users表内的数据delete from users3.把临时表用户加到users表中,并将默认upwd全设为1234要看你upwd是什么数据类型 如果是数字的就insert users select uname,1234 from#a是字符型的insert users select uname,'1234' from#a4.最后删除临时表drop table#a这样所有人的初始密码都变为1234

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
访问手机版