请问怎么给重复名字加个编号
比如有两个张三,两个李四,改成张三1,张三2,李四1,李四2求教大佬们~~~急
DECLARE @t TABLE( id INT, name VARCHAR(10)) INSERT @t VALUES ( 1, '王五' ), ( 2, '王五' ), ( 3, '王五' ), ( 4, '李三' ), ( 5, '王五' ), ( 6, '赵四' ), ( 10, '田强' ), ( 15, '田强' ), ( 18, '李三' ) SELECT * FROM @t AS T DECLARE @th TABLE( rank1 INT, id INT, name VARCHAR(10)) INSERT @th SELECT ROW_NUMBER() OVER (PARTITION BY name ORDER BY T.id ), T.id, T.name FROM @t AS T UPDATE T SET T.name += CONVERT(VARCHAR(20), T2.rank1) FROM @t AS T JOIN @th AS T2 ON T2.id = T.id SELECT * FROM @t AS T ORDER BY T.id
[此贴子已经被作者于2021-4-27 15:30编辑过]