sql语句查询表中重复数据(多类型)创新互联

2022-04-21    分类: 网站导航

表名:hztj

字段名:edxzqhdm ,sdxzqhdm

1.查出某一列数据中重复的,以sdxzqhdm为例

select * from hztj a where (a.sdxzqhdm) in (select sdxzqhdm from hztj group by sdxzqhdm having count(*) > 1)


2.查询出所有数据进行分组之后,和重复数据的重复次数的查询数据

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

查询及删除重复记录的方法

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

select * from hztj

where sdxzqhdm in (select sdxzqhdm from hztj group by sdxzqhdm having count(sdxzqhdm) > 1)

(2)删除表中多余的重复记录,重复记录是根据单个字段来判断,只留rowid最小的记录

delete from hztj

where sdxzqhdm in (select sdxzqhdm from hzth group  by  sdxzqhdm having  count(sdxzqhdm) > 1)
and rowid not in (select min(rowid) from  hztj group by sdxzqhdm having count(sdxzqhdm)>1)

(3)查找表中多余的重复记录(多个字段)
select * from hztj a
where (a.sdxzqhdm,a.edxzqhdm) in (select sdxzqhdm,edxzqhdm from hztj group by sdxzqhdm,edxzqhdm having count(*) > 1)

(4)删除表中多余的重复记录(多个字段),只留有rowid最小的记录

delete from hztj a

where (a.sdxzqhdm,a.edxzqhdm) in (select sdxzqhdm,edxzqhdm from hztj group by sdxzqhdm,edxzqhdm having count(*) > 1) 
and rowid not in (select min(rowid) from hztj group by sdxzqhdm,edxzqhdm having count(*)>1)

(5)查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select * from hztj a
where (a.sdxzqhdm,a.edxzqhdm) in  (select sdxzqhdm,edxzqhdm from hztj group by sdxzqhdm,edxzqhdm having count(*) > 1)
and rowid not in (select min(rowid) from hztj group by sdxzqhdm,edxzqhdm having count(*)>1)

网站名称:sql语句查询表中重复数据(多类型)创新互联
网页地址:https://www.cdcxhl.com/news1/146101.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有网站建设网站导航

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

外贸网站制作