度量快速开发平台-专业、快速的软件定制快开平台
标题: SQL重复记录查询常用语句 [打印本页]
作者: 万望 时间: 2020-3-8 11:12
大神,太给力~\(≧▽≦)/~啦啦啦
作者: 陈晓龙 时间: 2020-3-8 17:42
是呢!
作者: 陈晓龙 时间: 2020-3-8 17:44
还可以撒!
作者: 陈晓龙 时间: 2020-3-8 17:45
作者: 陈晓龙 时间: 2020-3-29 15:03
你都学会了吗》
作者: 王爱东 时间: 2020-7-28 09:18
不过,这些语法在工作中随时能用到。
作者: 张兴康 时间: 2020-7-28 12:06
见到好东西得收藏
作者: 陈晓龙 时间: 2020-7-28 18:32
标题: SQL重复记录查询常用语句
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select * from people
where peopleId in (select peopleId from people group by peopleId having count
(peopleId) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
delete from people
where 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 a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having
count(*) > 1)
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from vitae a
where (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 vitae group by peopleId,seq having count(*)>1)
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select * from vitae a
where (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 vitae group by peopleId,seq having count(*)>1)
欢迎光临 度量快速开发平台-专业、快速的软件定制快开平台 (http://bbs.delit.cn/) |
Powered by Discuz! X3.2 |