Sql Server
表中有多条重复数据,如何使用sql语句删除表中重复数据,并要求只保留一条数据?
------解决方案--------------------最简单的,重复的数据只取max或者min(1条)。
http://blog.163.com/yaxctgu@126/blog/static/16267031820112723924742/
------解决方案--------------------row_number() over(partition by xxx) as rowid 把rowid不是1的删除 不就好了
------解决方案--------------------这个得写存储过程
------解决方案--------------------建个临时表,把distinct数据导进去,删掉原数据,再导回。
------解决方案--------------------将不重复的记录全部选出来,存入临时表中,再删除原数据,将临时表中数据导回
------解决方案--------------------删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
delete from people
where peopleName in (select peopleName from people group by peopleName having count(peopleName) > 1)
and peopleId not in (select min(peopleId) from people group by peopleName having count(peopleName)>1)
------解决方案--------------------同意7楼,将不重复的记录全部选出来,存入临时表中,再删除原数据,将临时表中数据导回 。