ZKX's LAB

sql中如何删除一个表中重复的记录? sql删除重复数据

2021-04-08知识9

SQL查询,如何去除重复的记录? sql查询去2113除重复值语句sql 单表/多表查询去除重5261复记录单表distinct多表group bygroup by 必须放在 order by 和 limit之前,不然会4102报错1、查找表中多余的重复记录,1653重复记录是根据单个字段(peopleId)来判断select*from peoplewhere peopleId in(select peopleId from people group by peopleId having count(peopleId)>;1)2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录delete from peoplewhere peopleId in(select peopleId from people group by peopleId having count(peopleId)>;1)and rowid not in(select min(rowid)from people group by peopleId having count(peopleId)>;1)3、查找表中多余的重复记录(多个字段)select*from vitae awhere(a.peopleId,a.seq)in(select peopleId,seq from vitae group by peopleId,seq having count(*)>;1)4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录delete from vitae awhere(a.peopleId,a.seq)in(select peopleId,seq from vitae group by peopleId,seq having count(*)>;1)and rowid not in(select min(rowid)from 。

SQL 删除重复数据 select distinct*into#Tmp_aa from tableName 把不重复的找出来插入到临时表drop table tableName 删掉原来的表select*into tableName from#Tmp_aa 把临时表插入到新建的tableNamedrop table#Tmp_aa 删掉临时表

SQL删除重复数据 重复记录是根据“货品”判断,如果只留有“规格”最小的记录delete from 表where 货品 in(select 货品 from 表 group by 货品 having count(货品)>;1)and 规格 not in(select min(规格)from 表 group by 货品 having count(货品)>;1)如果换成“规格”最大的那下面AND 规格 in 就可以了!如果是根据单位来删除就把规格替换成单位就行了!

随机阅读

qrcode
访问手机版