Mysql - 如何使用另一列的值加上一些字符串更新一列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2227783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 15:14:37  来源:igfitidea点击:

Mysql - How to update a column using another column's value plus some strings

mysql

提问by aeran

I have a table with the following column & value:

我有一个包含以下列和值的表:

ColA = "8765" ColB = "2137"

ColA = "8765" ColB = "2137"

I would like to update ColB in the same table to the following value:

我想将同一个表中的 ColB 更新为以下值:

ColC = "[8765][2137]"

ColC = "[8765][2137]"

How can I do it using phpmyadmin (meaning just sql syntax)?

我怎样才能使用 phpmyadmin (意味着只是 sql 语法)?

回答by Select0r

UPDATE table SET ColC = CONCAT("[", ColA, "][", ColB, "]");

回答by dxh

UPDATE
    myTable
SET
    ColC = CONCAT('[', ColA, '][', ColB, ']')
--WHERE...

回答by user2446600

Use only this one! I've tested on the live server.

只用这个! 我已经在实时服务器上进行了测试。

UPDATE table SET column_name = CONCAT( Column_A, ' ', Column_A );

In between single quotes will add a space. You can remove that if it is not required.

在单引号之间会添加一个空格。如果不需要,您可以将其删除。