转自:http://www.maomao365.com/?p=4942
**row_number函数在数据库中的功能是为每一行 按照一定的规则生成一个编号,
我们常常利用这一属性,对表进行分页操作,
下文我们将讲述采用 row_number函数删除表中重复数据行**
create table A(keyId int,info varchar(200))
go
insert into A(keyId,info)values
(1,'a'),(2,'b'),(3,'C'),(4,'d'),(5,'e'),
(1,'a'),(21,'b1'),(31,'C1'),(4,'d'),(51,'猫猫小屋'),
(1,'a'),(6,'b1'),(7,'C1'),(4,'d000'),(10,'maomao365.com')
go
delete [A2] from
(select row_number() over (Partition By keyId order by keyId) as keyId2,* from A ) as [A2]
where [A2].keyId2 >1
delete [A2] from
(select row_number() over (Partition By keyId,info order by keyId) as keyId2,* from A ) as [A2]
where [A2].keyId2 >1
*/
select * from A
go
truncate table A
drop table A
go