如何将字符串附加到 MySQL 中的现有字段?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3765631/
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
How can I append a string to an existing field in MySQL?
提问by Matt Elhotiby
I want to update the code on all my record to what they currently are plus _standard any ideas?
我想将我所有记录上的代码更新为它们当前的代码以及 _standard 有什么想法吗?
So for example if the codes are apple_1 and apple_2 I need them to be apple_1_standard and apple_2_standard
例如,如果代码是 apple_1 和 apple_2,我需要它们是 apple_1_standard 和 apple_2_standard
Before:
前:
id code
------------
1 apple_1
1 apple_2
Psuedo Query:
伪查询:
update categories set code = code + "_standard" where id = 1;
Expected result:
预期结果:
id code
----------------------
1 apple_1_standard
1 apple_2_standard
回答by Daniel Vassallo
回答by gus
Update image field to add full URL, ignoring null fields:
更新图像字段以添加完整 URL,忽略空字段:
UPDATE test SET image = CONCAT('https://my-site.com/images/',image) WHERE image IS NOT NULL;