【 전 】 SQL 삭제, 중복 기록 삭제
5095 단어 sql
--
, , ,
a b c d
1 2 3 4
1 5 3 5
1 2 7 9
a、b , a、b , , 1 2 3 4 1 2 7 9
:
a b c d
1 2 3 4
1 5 3 5
a b c d
1 5 3 5
1 2 7 9
sql
CREATE TABLE Tb1(id int, [a] varchar(255), [b] varchar(255), [c] varchar(255), [d] varchar(255))
INSERT Tb1(id, [a], [b], [c], [d])
SELECT 1, '1','2','3','4'
UNION ALL SELECT 2, '1','5','3','5'
UNION ALL SELECT 3, '1','2','7','9'
UNION ALL SELECT 4, '1','4','7','6'
delete Tb1 where [id] not in (select max([id]) from Tb1 group by a,b )
select * from tb1
drop table tb1
:
a b c d
1 5 3 5
:
delete m from tb t
inner join
(
select a ,b
from tb
group by a , b
having count(*)>1
)n
on m.a = n.a and m.b = n.b
delete * from tb as m,
(
select a ,b
from tb
group by a , b
having count(*)>1
)n
where m.a = n.a and m.b = n.b
------------------------------------------------------------------------------------
, , 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)
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
------------------------------------------------------------------------------------------------
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 = @id
fetch cur_rows into @id,@max
end
close cur_rows
set rowcount 0
, , , , Name , 。
1、 , ,
select distinct * from tableName
。
( 1 ),
select distinct * into #Tmp from tableName
drop table tableName
select * into tableName from #Tmp
drop table #Tmp
, 。
2、 ,
Name,Address,
select identity(int,1,1) as autoID, * into #Tmp from tableName
select min(autoID) as autoID into #Tmp2 from #Tmp group by Name,autoID
select * from #Tmp where autoID in(select autoID from #tmp2)
select Name,Address ( autoID , select )
select * from tablename where id in (
select id from tablename
group by id
having count(id) > 1)
--18
DELETE FROM AQSIQ_CLDRC WHERE CODE IN (
SELECT MAX(CODE),NGRNAME FROM
(
SELECT * FROM AQSIQ_CLDRC WHERE HBDATE='2013-04-18' AND PARAM2='0' and swrc is null and xwrc is null
)
GROUP BY HBDATE,NGRNAME
)
SELECT * FROM AQSIQ_CLDRC WHERE NGRNAME IN
( -- 18 1 , ngrname
SELECT NGRNAME FROM AQSIQ_CLDRC WHERE HBDATE='2013-04-18' GROUP BY NGRNAME HAVING COUNT(*)>1
)
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
깊이 중첩된 객체를 정확히 일치 검색 - PostgreSQL목차 * 🚀 * 🎯 * 🏁 * 🙏 JSON 객체 예시 따라서 우리의 현재 목표는 "고용주"사용자가 입력한 검색어(이 경우에는 '요리')를 얻고 이 용어와 정확히 일치하는 모든 사용자 프로필을 찾는 것입니다. 즐거운 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.