gpt4 book ai didi

sql - 如何替换SQL中列中相等的值?

转载 作者:行者123 更新时间:2023-12-04 16:13:53 26 4
gpt4 key购买 nike

我在表中有一列具有相同的字符串值。我需要替换相等的字符串,例如:

+----+-------------+
| ID | Column_Name |
+----+-------------+
| 1 | Imports |
| 2 | Imports |
| 3 | Exports |
| 4 | Exports |
+----+-------------+

需要替换为:

+----+-------------+
| ID | Column_Name |
+----+-------------+
| 1 | Imports1 |
| 2 | Imports2 |
| 3 | Exports1 |
| 4 | Exports2 |
+----+-------------+

有没有办法在 SQL 查询中实现这一点?

The purpose of doing this is that I'm using the 'Column_Name' string values in the dynamic SQL to replace the Integer values because of the same names the different values for the column are not getting replaced.

最佳答案

你可以试试这个:

UPDATE Your_Table
SET Name = Name + CAST(RN AS varchar(1)) FROM -- varchar(10)
(SELECT ROW_NUMBER() OVER(PARTITION BY Name ORDER BY ID) AS RN
FROM Your_Table) AS A

关于sql - 如何替换SQL中列中相等的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34127146/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com