日期:2014-05-17  浏览次数:20353 次

高分求如何删除多个字段存在重复的记录
例如
里面有多条记录出现 重复,我只保留里面唯一的一条记录,里面涉及到多个字段同样的重复,怎么删除

Company CN-2811-0911 520.0000 C  2011-2-20 0:00:00 
Company CN-2811-0911 520.0000 C  2011-2-20 0:00:00 --删掉
Company CN-278X-2011 40.0000 C  2011-2-20 0:00:00 
Company CN-278X-2011 40.0000 C  2011-2-20 0:00:00 --删掉
Company CN-267X-1411 52.0000 C  2011-2-20 0:00:00 
Company CN-267X-1411 52.0000 C  2011-2-20 0:00:00 --删掉
Company CN-2186-3011 320.0000 C  2011-2-20 0:00:00 
Company CN-2186-3011 320.0000 C  2011-2-20 0:00:00 --删掉
Company CN-2145-2711 40.0000 C  2011-2-20 0:00:00 
Company CN-2145-2711 40.0000 C  2011-2-20 0:00:00 --删掉
Company CN-2145-0411 416.0000 

------最佳解决方案--------------------

--建表
create table #Enterprise (a varchar(20), b varchar(20), c float, d char(1), e datetime)
--写入数据
insert into #Enterprise
select 'Company', 'CN-2811-0911',520.0000,'C','2011-2-20 0:00:00' union all
select 'Company', 'CN-2811-0911',520.0000,'C','2011-2-20 0:00:00' union all
select 'Company', 'CN-278X-2011',40.0000,'C','2011-2-20 0:00:00' union all
select 'Company', 'CN-278X-2011',40.0000,'C','2011-2-20 0:00:00' union all
select 'Company', 'CN-267X-1411',52.0000,'C','2011-2-20 0:00:00' union all
select 'Company', 'CN-267X-1411',52.0000,'C','2011-2-20 0:00:00' union all
select 'Company', 'CN-2186-3011',320.0000,'C','2011-2-20 0:00:00' union all
select 'Company', 'CN-2186-3011',320.0000,'C','2011-2-20 0:00:00' union all
select 'Company', 'CN-2145-2711',40.0000,'C','2011-2-20 0:00:00' union all
select 'Company', 'CN-2145-2711',40.0000,'C','2011-2-20 0:00:00' union all
select 'Company', 'CN-2145-0411',416.0000,null,null
--数据处理
select * into #Temp from #Enterprise group by a,b,c,d,e
--删除表
delete from #Enterprise 
--导回数据
insert into #Enterprise
select * from #temp
--原表数据
select * from #Enterprise
------
a                    b                    c                      d    e
-------------------- -------------------- ---------------------- ---- -----------------------
Company              CN-2145-0411         416                    NULL NULL
Company              CN-2145-2711         40                     C&nb