SQL 은 중복 데 이 터 를 조회 하고 중복 횟수 를 표시 합 니 다.
5180 단어 데이터 뱅 크
select * from F group by a,b,c,d having count(*)>1
,
select distinct * into #Tmp from tableName
drop table tableName
select * into tableName from #Tmp
drop table #Tmp
SQL 중복 데이터 삭제 방법
예 를 들 면: id name value 1 a pp 2 a pp 3 b iii 4 b pp 5 b pp 6 c pp 7 c pp 8 c iii id 는 메 인 키 이런 결 과 를 요구 하 다 id name value 1 a pp 3 b iii 4 b pp 6 c pp 8 c iii
방법 1 delete YourTable where [id] not in ( select max([id]) from YourTable group by (name + value)) 방법 2 delete a from 시계. a left join( select id=min(id) from 시계. group by name,value )b on a.id=b.id where b.id is null 중복 기록 을 조회 및 삭제 하 는 SQL 문장 조회 및 중복 기록 을 삭제 하 는 SQL 문장 1, 검색 표 에 남아 있 는 중복 기록, 중복 기록 은 단일 필드 (peopleId) 에 따라 select * from people where peopleId in (select) 을 판단 합 니 다. peopleId from people group by peopleid having count (peopleid) > 1) 2. 테이블 에 남아 있 는 중복 기록 을 삭제 합 니 다. 중복 기록 은 단일 필드 (peopleid) 에 따라 판단 되 며, rowid 의 가장 작은 기록 만 남 겨 둡 니 다 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, 테이블 에 남아 있 는 중복 기록 찾기 (여러 필드) select * from vitae a where (a. peopleid, a. seq) in (select peopleid, seq from vitae group by peopleid, seq having count (*) > 1) 4, 테이블 에 남아 있 는 중복 기록 (여러 필드) 을 삭제 하고 rowid 의 가장 작은 기록 만 남 겨 둡 니 다 delete from vitae a where (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. 테이블 에 남아 있 는 중복 기록 (여러 필드) 을 찾 습 니 다. rowid 의 최소 기록 select * from vitae a where (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) (2) 예 를 들 어 A 표 에 필드 "name" 이 존재 하고 서로 다른 기록 간 의 "name" 값 이 같 을 수 있 습 니 다. 이 표 에 있 는 각 기록 사 이 를 조회 해 야 합 니 다."name" 값 에 중복 되 는 항목 이 있 습 니 다. Select Name, Count (*) From A Group By Name Having Count (*) > 1 성별 도 같 으 면 다음 과 같 습 니 다. Select Name, sex, Count (*) From A Group By Name, sex Having Count (*) > 1
(3) 방법 1 declare @ max integer, @ id integer declare cur rows cursor local for select 주 필드, count (*) from 표 명 group by 주 필드 having count (*)>; 1 open cur rows fetch cur rows into @ id, @ max while @ fetch status = 0 begin select @ max = @ max - 1 set rowcount @ max delete from 표 이름 where main 필드 = @ id fetch cur rows into @ id, @ max end close cur rows set rowcount 0
방법 2 '중복 기록' 은 두 가지 의미 의 중복 기록 이 있 습 니 다. 하 나 는 완전히 중복 되 는 기록, 즉 모든 필드 가 중복 되 는 기록 입 니 다. 다른 하 나 는 일부 관건 적 인 필드 가 중복 되 는 기록 입 니 다. 예 를 들 어 Name 필드 가 중복 되 거나 다른 필드 가 중복 되 지 않 아 도 무시 할 수 있 습 니 다. 1. 첫 번 째 중복 에 대해 쉽게 해결 할 수 있 습 니 다. select distinct * from table N 을 사용 합 니 다.ame 는 중복 기록 이 없 는 결과 집합 을 얻 을 수 있 습 니 다. 이 표 에서 중복 기록 을 삭제 해 야 한다 면 (중복 기록 은 1 개 유지)다음 방법 으로 select distinct * into \ # Tmp from table Name drop table Name select * into table Name from \ # Tmp drop table \ # Tmp 에서 이러한 중복 이 발생 하 는 이 유 는 표 디자인 이 주도면밀 하지 않 아 유일한 색인 열 을 추가 하면 해결 할 수 있 기 때 문 입 니 다. 2. 이러한 중복 문 제 는 보통 중복 기록 의 첫 번 째 기록 을 유지 해 야 합 니 다. 조작 방법 은 다음 과 같 습 니 다.중 복 된 필드 가 Name, Address 라 고 가정 하면 이 두 필드 의 유일한 결과 집합 select idenity (int, 1, 1) as autoID, * into \ # Tmp from table Name selectmin (autoID) as autoID into \ # Tmp 2 from \ # Tmp group by Name, autoID select * from \ # Tmp where autoID in (select autoID from \ # tmp 2)마지막 select 는 Name, Address 가 중복 되 지 않 는 결과 집합 을 얻 었 습 니 다. (그러나 autoID 필드 가 하나 더 생 겼 습 니 다. 실제 쓸 때 select 자구 에 이 열 을 생략 할 수 있 습 니 다.) (4) 중복 select * from tablename where id in (selection id from tablename group by id having count (id) > 1)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
nginx websocket ip_해시 규칙프로젝트 를 다운로드 한 후 서로 다른 네트워크 에 각각 이 demo 프로젝트 를 배치 합 니 다. 프로젝트 에서 환경 변수 에 따라 시스템 변 수 를 설정 합 니 다. spring.profiles.active=de...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.