select distinct * into #a from tablenam where username in (select max(username) from a group by username having (*)>1)delete a from a a,#a b where a.username=b.username and a.age=b.age insert into a (usernaem,age) select username,age from #a 不知道你的字段名,所以你参考一下以上的语句
这样:while exists (select a,b,c,... from tablename group by a,b,c,... having count(*)>1) --如果还有重复,继续删除 begin set rowcount 1 delete a from tablename a,(select a,b,c,... from tablename group by a,b,c,... having count(*)>1) as b where a.a=b.a and a.b=b.b and ... set rowcount 0 end
delete sf FROM TABLE1 k JOIN TABLE1 sf ON sf.id < k.id and sf.we=k.we
select distinct *
into #a
from tablenam
where username in
(select max(username)
from a
group by username
having (*)>1)delete a from a a,#a b where a.username=b.username and a.age=b.age insert into
a (usernaem,age)
select username,age from #a 不知道你的字段名,所以你参考一下以上的语句
begin
set rowcount 1
delete a
from tablename a,(select a,b,c,... from tablename group by a,b,c,... having count(*)>1) as b
where a.a=b.a and a.b=b.b and ...
set rowcount 0
end
FROM TABLE1 k JOIN
TABLE1 sf ON sf.id < k.id
and sf.we=k.we