日期:2014-05-17 浏览次数:20616 次
if object_id('tb') is not null
drop table tb
go
create table tb([电话] bigint,[姓名] varchar(6))
insert tb
select 13300001111,'张三' union all
select 13300001111,'李四' union all
select 13300001111,'鬼子' union all
select 18877776666,'老先生'
go
;with t
as
(
select *,
ROW_NUMBER() over(partition by [电话]
order by @@servername) as rownum
from tb
)
--删除多余的数据
delete from t where rownum > 1
--查询数据,发现多余数据已经删除
select *
from tb
/*
电话 姓名
13300001111 张三
18877776666 老先生
*/