欢迎投稿

今日深度:

sql查出一张表中重复的所有记录数据的三种方法

sql查出一张表中重复的所有记录数据的三种方法,sql三种方法


查询重复的数据

1.查询出所有数据进行分组之后,和重复数据的重复次数的查询数据,先列下:

select  count(username) as '重复次数',username from xi group by username  having count(*)>1 order by username desc

2.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断

select * from people
where peopleId in (select  peopleId  from  people  group  by  peopleId  having  count(peopleId) > 1)

3.查找表中多余的重复记录(多个字段)

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

www.htsjk.Com true http://www.htsjk.com/Sql_Server/24606.html NewsArticle sql查出一张表中重复的所有记录数据的三种方法,sql三种方法 查询重复的数据 1.查询出所有数据进行分组之后,和重复数据的重复次数的查询数据,先列下: select count(username) as 重复次...
评论暂时关闭