数据库重复替换
有一个userinfo 表,把name字段有重复的值替换成原先name+[1-n]
比如 name中有重复n个"a" 替换成a1,a2 , a3, a4, a5...an
------解决方案--------------------select *,name+rtrim(select row_number() over(partition by name order by getdate())) from userinfo
------解决方案--------------------;with cte as
(select *, Case (ROW_NUMBER() over(partition by name order by GetDate())-1) when 0 then Name else Name+rtrim(ROW_NUMBER() over(partition by Name order by GetDate())-1) end as nID from userinfo)
update cte set name=nID