程序代码:
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编辑过]