我正在使用SQL Server 2008 R2。我有一张桌子DESTI
CODE_DESTI ENTERPRISE
-----------------------
1 xx
1 yy
12 pp
12 oo
12 ll
如何在
之后用自动增量1号更新重复的CODE_DESTI
CODE_DESTI ENTERPRISE
-----------------------
11 xx
12 yy
121 pp
122 oo
123 ll
答案 0 :(得分:1)
您可以使用Window函数执行此操作:
SELECT
CODE_DESTI + CAST(RANK() AS varchar) OVER (PARTITION BY CODE_DESTI ORDER BY ENTERPRISE) AS CODE_DESTI,
ENTERPRISE
FROM DESTI