我的表有两列,我需要将这两列连接起来并用结果更新第一列。
例如,假设这是我的表:
+----+-------+-------+
| id | col1 | col2 |
+----+-------+-------+
| 1 | text1 | text2 |
+----+-------+-------+
| 2 | text3 | text4 |
+----+-------+-------+
连接后,我的表应为:
+----+-------------+-------+
| id | col1 | col2 |
+----+-------------+-------+
| 1 | text1.text2 | text2 |
+----+-------------+-------+
| 2 | text3.text4 | text4 |
+----+-------------+-------+
如何使用SQL做到这一点?
最佳答案
试试这个(对于MySQL)
UPDATE your_table
SET col1 = CONCAT_WS('.', col1, col2)
这对于MS-SQL
UPDATE your_table
SET col1 =col1 || "." || col2
关于sql - 合并两个表列,并用结果更新其中一个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8384688/