首頁 > 資料庫 > Oracle > 主體

oracle怎麼查詢重複的數據

WBOY
發布: 2022-02-28 11:14:44
原創
39525 人瀏覽過

在oracle中,可以利用count()函數來配合select查詢語句來查詢重複的數據,語法為「select userCode from user group by userCode having count(userCode)>1」。

oracle怎麼查詢重複的數據

本教學操作環境:Windows10系統、Oracle 11g版、Dell G3電腦。

oracle怎麼查詢重複的資料

1、查找表中多餘的重複記錄,重複記錄是根據單一欄位(userCode)來判斷

select 
    * 
from 
    user
where 
    userCode
in 
    (select  userCode  from  user group by  userCode having count (userCode) > 1)
登入後複製

2、刪除表中多餘的重複記錄,重複記錄是根據單一欄位(userCode)來判斷,只留有rowid最小的記錄

delete from 
    user 
where 
    userCode 
in 
    (select userCode from user group by  userCode having count (peopleId) > 1)
and rowid not in 
    (select min(rowid) from   user group by userCode having count(userCode)>1)
登入後複製

3、查找表中多餘的重複記錄(多個欄位)

select 
    * 
from 
    user a
where 
    (a.userCode,a.userName) 
in  
    (select userCode,userName from user group by userCode,userName having count(*) > 1)
登入後複製

4、刪除表中多餘的重複記錄(多個欄位),只留有rowid最小的記錄

delete from 
    user a
where
    (a.userCode,a.userName) 
in   
    (select userCode,userName from user group by userCode,userName having count(*) > 1)
and rowid not in 
    (select min(rowid) from user group by userCode,userName having count(*)>1)
登入後複製

5、查找表中多餘的重複記錄(多個欄位),不包含rowid最小的記錄

select 
    * 
from 
    user a
where 
    (a.userCode,a.userName)  
in   
    (select userCode,userName from user group by userCode,userName having count(*) > 1)
and rowid not in 
    (select min(rowid) from user group by userCode,userName having count(*)>1)
登入後複製

推薦教學:《Oracle影片教學

以上是oracle怎麼查詢重複的數據的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!