select [key] from test group by [key] having count(1)>=2
假设 a,b..是联合主键 select * from yourTable A where (select count(1) from yourTable where a=A.a and b=A.b ..) > 1
不用这么复杂吧假设 a,b..是联合主键 select a,b,count(*) as 记录数 from yourTable group a,b having count(*)>=2
Declare @Student Table(Id int,SName Varchar(10),Score Int) Insert @Student Select 1,'张三',69 Union all Select 2,'李四',89 Union all Select 3,'张三',69select * from @Studentdelete from @Student where id not in ( select min(id) from @Student group by SName,Score )select * from @Student
上面是以前一个帖子的, 像你的情况你可以生成一个临时表先select id=identity(int,1,1),* from yourtablename再对临时表进行处理
from test
group by [key]
having count(1)>=2
select * from yourTable A where (select count(1) from yourTable where a=A.a and b=A.b ..) > 1
select a,b,count(*) as 记录数 from yourTable
group a,b
having count(*)>=2
Insert @Student Select 1,'张三',69
Union all Select 2,'李四',89
Union all Select 3,'张三',69select * from @Studentdelete from @Student where id not in
(
select min(id)
from @Student
group by SName,Score
)select * from @Student
像你的情况你可以生成一个临时表先select id=identity(int,1,1),* from yourtablename再对临时表进行处理