sql語(yǔ)句查詢(xún)表中重復(fù)數(shù)據(jù)(多類(lèi)型)創(chuàng)新互聯(lián)

2022-04-21    分類(lèi): 網(wǎng)站導(dǎo)航

表名:hztj

字段名:edxzqhdm ,sdxzqhdm

1.查出某一列數(shù)據(jù)中重復(fù)的,以sdxzqhdm為例

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


2.查詢(xún)出所有數(shù)據(jù)進(jìn)行分組之后,和重復(fù)數(shù)據(jù)的重復(fù)次數(shù)的查詢(xún)數(shù)據(jù)

select  count(sdxzqhdm) as '重復(fù)次數(shù)',sdxzqhdm from hztj group by sdxzqhdm having count(*)>1 order by sdxzqhdm desc

查詢(xún)及刪除重復(fù)記錄的方法

(1)查找表中多余的重復(fù)記錄,重復(fù)記錄是根據(jù)單個(gè)字段來(lái)判斷 ,如:

select * from hztj

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

(2)刪除表中多余的重復(fù)記錄,重復(fù)記錄是根據(jù)單個(gè)字段來(lái)判斷,只留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)查找表中多余的重復(fù)記錄(多個(gè)字段)
select * from hztj a
where (a.sdxzqhdm,a.edxzqhdm) in (select sdxzqhdm,edxzqhdm from hztj group by sdxzqhdm,edxzqhdm having count(*) > 1)

(4)刪除表中多余的重復(fù)記錄(多個(gè)字段),只留有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)查找表中多余的重復(fù)記錄(多個(gè)字段),不包含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)

網(wǎng)站名稱(chēng):sql語(yǔ)句查詢(xún)表中重復(fù)數(shù)據(jù)(多類(lèi)型)創(chuàng)新互聯(lián)
網(wǎng)頁(yè)地址:http://www.bm7419.com/news1/146101.html

網(wǎng)站建設(shè)、網(wǎng)絡(luò)推廣公司-創(chuàng)新互聯(lián),是專(zhuān)注品牌與效果的網(wǎng)站制作,網(wǎng)絡(luò)營(yíng)銷(xiāo)seo公司;服務(wù)項(xiàng)目有網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作