【网学网提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。网学会员整理了重复记录的几个SQL语法的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
分享--针对重复记录的几个实用的SQL语法
在对数据进行分析处理时,有时候会遇到要处理重复记录的问题,
下面分享下针对重复记录的几个SQL语法。
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
select*frompeople
wherepeopleIdin(selectpeopleIdfrompeoplegroupbypeopleIdhavingcount
(peopleId)>1)
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
deletefrompeople
wherepeopleIdin(selectpeopleIdfrompeoplegroupbypeopleIdhavingcount
(peopleId)>1)
androwidnotin(selectmin(rowid)frompeoplegroupbypeopleIdhavingcount(peopleId
)>1)
3、查找表中多余的重复记录(多个字段)
select*fromvitaea
where(a.peopleId,a.seq)in(selectpeopleId,seqfromvitaegroupbypeopleId,seqhaving
count(*)>1)
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
deletefromvitaea
where(a.peopleId,a.seq)in(selectpeopleId,seqfromvitaegroupbypeopleId,seqhaving
count(*)>1)
androwidnotin(selectmin(rowid)fromvitaegroupbypeopleId,seqhavingcount(*)>1)
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select*fromvitaea
where(a.peopleId,a.seq)in(selectpeopleId,seqfromvitaegroupbypeopleId,seqhaving
count(*)>1)
androwidnotin(selectmin(rowid)fromvitaegroupbypeopleId,seqhavingcount(*)>1)