1)"입니다."/> 1)"입니다.">

 >  기사  >  데이터 베이스  >  Oracle에서 중복 필드를 쿼리하는 방법

Oracle에서 중복 필드를 쿼리하는 방법

WBOY
WBOY원래의
2022-01-21 11:41:337939검색

Oracle에서는 count() 함수를 사용하여 반복되는 필드를 쿼리할 수 있습니다. 구문은 "select * from table name where field in(select field from table name group by field with count (field) >1)"입니다.

Oracle에서 중복 필드를 쿼리하는 방법

이 튜토리얼의 운영 환경: Windows 10 시스템, 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) 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 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.