SQL重復(fù)記錄查詢的幾種方法建站知識(shí)
導(dǎo)讀:1建站知識(shí)SQL重復(fù)記錄查詢的幾種方法,需要的朋友可以參考一下營(yíng)銷型網(wǎng)站建設(shè)網(wǎng)seo優(yōu)化趨勢(shì)。
1、查找表中多余的重復(fù)記錄,重復(fù)記錄是根據(jù)單個(gè)字段(peopleId)來判斷
復(fù)制代碼 代碼如下:
select * from peoplewhere peopleId in (select peopleId from people group by peopleId having count
(peopleId) > 1)
2、刪除表中多余的重復(fù)記錄,重復(fù)記錄是根據(jù)單個(gè)字段(peopleId)來判斷,只留有rowid最小的記錄復(fù)制代碼 代碼如下:
delete from people where peopleId in (select peopleId from people group by peopleId having count
(peopleId) > 1)and rowid not in (select min(rowid) from people group by peopleId having count(peopleId
)>1)
3、查找表中多余的重復(fù)記錄(多個(gè)字段)復(fù)制代碼 代碼如下:
select * from vitae awhere (a.peopleId,a.seq) in (select peopleId,seq from vitae group by peopleId,seq having
count(*) > 1)
4、刪除表中多余的重復(fù)記錄(多個(gè)字段),只留有rowid最小的記錄復(fù)制代碼 代碼如下:
delete from vitae awhere (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)
5、查找表中多余的重復(fù)記錄(多個(gè)字段),不包含rowid最小的記錄復(fù)制代碼 代碼如下:
select * from vitae awhere (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)seo網(wǎng)站優(yōu)化軟件
(二)比方說在A表中存在一個(gè)字段“name”,而且不同記錄之間的“name”值有可能會(huì)相同,現(xiàn)在就是需要查詢出在該表中的各記錄之間,“name”值存在重復(fù)的項(xiàng);復(fù)制代碼 代碼如下:
Select Name,Count(*) From A Group By Name Having Count(*) > 1
如果還查性別也相同大則如下:復(fù)制代碼 代碼如下:
Select Name,sex,Count(*) From A Group By Name,sex Having Count(*) > 1
(三)方法一復(fù)制代碼 代碼如下:
declare @max integer,@id integerdeclare cur_rows cursor local for select 主字段,count(*) from 表名 group by 主字段 having
count(*) >; 1open cur_rowsfetch cur_rows into @id,@maxwhile @@fetch_status=0beginselect @max = @max -1set rowcount @maxdelete from 表名 where 主字段 = @idfetch cur_rows into @id,@maxendclose cur_rowsset rowcount 0
方法二有兩個(gè)意義上的重復(fù)記錄,一是完全重復(fù)的記錄,也即所有字段均重復(fù)的記錄,二是部分關(guān)鍵字段重
復(fù)的記錄,比如Name字段重網(wǎng)站seo優(yōu)化培訓(xùn)復(fù),而其他字段不一定重復(fù)或都重復(fù)可以忽略。
1、對(duì)于第一種重復(fù),比較容易解決,使用
聲明: 本文由我的SEOUC技術(shù)文章主頁(yè)發(fā)布于:2023-05-24 ,文章SQL重復(fù)記錄查詢的幾種方法建站知識(shí)主要講述幾種方法,標(biāo)簽,SQL網(wǎng)站建設(shè)源碼以及服務(wù)器配置搭建相關(guān)技術(shù)文章。轉(zhuǎn)載請(qǐng)保留鏈接: http://www.bifwcx.com/article/web_6693.html
為你推薦與SQL重復(fù)記錄查詢的幾種方法建站知識(shí)相關(guān)的文章
-
通王TWCMS 2.0.3網(wǎng)站模板程序下載
(126)人喜歡 2024-01-15 -
Windows官方原版在哪里下載
(175)人喜歡 2024-01-15 -
WordPress網(wǎng)站模板發(fā)帖標(biāo)題顏色設(shè)置
(131)人喜歡 2024-01-07 -
修改discuz論壇帖子標(biāo)題80字符的長(zhǎng)度限制
(249)人喜歡 2024-01-07 -
wordpress程序調(diào)用不帶超鏈接的Tag標(biāo)簽
(234)人喜歡 2024-01-05 -
網(wǎng)站在不同時(shí)期需調(diào)整內(nèi)容更新的方向
(112)人喜歡 2023-08-12