sql 查询重复记录 收藏
发布日期:2021-05-13 07:42:00 浏览次数:14 分类:博客文章

本文共 3775 字,大约阅读时间需要 12 分钟。

 1
���������������������������������������������������������������������������peopleId������������
select 
* 
from
 people
where
 peopleId 
in
 (
select
  peopleId  
from
  people  
group
  
by
  peopleId  
having
  
count
(peopleId) 
> 
1
)
 ���������
 select * from testtable
 where numeber in (select number from people group by number having count(number) > 1 )
 ������������testtable������number���������������
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
)

 

���������http://www.cnblogs.com/congcong/archive/2008/11/07/1328834.html

������������

上一篇:ASP.NET Eval格式化汇总
下一篇:VS新建类自动添加版本注释

发表评论

最新留言

不错!
[***.144.177.141]2025年04月29日 20时52分16秒