美文网首页
SQL按重复数量查询重复记录

SQL按重复数量查询重复记录

作者: Time一柒 | 来源:发表于2020-06-02 15:05 被阅读0次

单个字段(重复数量大于二的)

select * from register_followyangxingpatient
where phone in (select phone from register_followyangxingpatient group by phone having count(phone) > 2)

多个字段

select * from vitae a
where (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having count(*) > 1)

查找表中多余的重复记录(多个字段),不包含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)

相关文章

网友评论

      本文标题:SQL按重复数量查询重复记录

      本文链接:https://www.haomeiwen.com/subject/rnmuzhtx.html