日期:2014-05-18  浏览次数:20431 次

删除重复行
表a
groupnum B
1 11
1 11
1 10
2 11 
2 20
2 20
2 11
2 15
3 23
3 23
3 15
3 6
3 6
3 6
...
...删除每组(groupnum)里有重复的行只保留一条

------解决方案--------------------
SQL code

--sql2000等高手来,我来个一通俗的
select distinct * into #tmp from a
delete from a
insert into a select * from #tmp
drop table #tmp
--sql 2005
delete from a
from (select row_number() over(partition by groupnum,B order by groupnum,B ) n,* from a) as a
where n!=1