Oracle で重複フィールドをクエリする方法

WBOY
リリース: 2022-01-21 11:41:33
オリジナル
7945 人が閲覧しました

Oracle では、count() 関数を使用して繰り返しフィールドをクエリできます。構文は、「select * from table name where field in (select field from table name group by field getting count (field) >」です。 1)」。

Oracle で重複フィールドをクエリする方法

このチュートリアルの動作環境: Windows 10 システム、Oracle 11g バージョン、Dell G3 コンピューター。

Oracle で重複フィールドをクエリする方法

1. テーブル内の重複する重複レコードを検索します。重複レコードは 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. テーブル内の冗長な重複レコード (複数のフィールド) を見つけます。レコード

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 Tutorial"

以上がOracle で重複フィールドをクエリする方法の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!