MySQL Mysql追加列值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13926239/
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:48:45  来源:igfitidea点击:

Mysql append column value

mysql

提问by Aravindhan

I am having the table with the following structure

我有以下结构的表

      ----------------------------
       id                  content
      ---------------------------
        1                   abc
        2                   bca
      ---------------------------

I want to append the character 'd' with the field 'content' ... So i want the table structure as follows

我想在字段 'content' 中附加字符 'd' ... 所以我想要表结构如下

       ----------------------------
       id                  content
      ---------------------------
        1                   abcd
        2                   bca
      ---------------------------

How can i do this..

我怎样才能做到这一点..

回答by Dhinakar

If you want update the column from the Table then use below Query

如果要更新表中的列,请使用下面的查询

update table1 set content = concat(content,'d');

If you want to select the column concatenation with 'd; the use below Query

如果要选择带有 'd; 的列连接;下面使用查询

select id, concat(content,'d') as content from table1;

Refer :

参考 :

http://sqlfiddle.com/#!2/099c8/1

http://sqlfiddle.com/#!2/099c8/1

回答by Mahmoud Gamal

You can use the CONCAT, like so

你可以CONCAT像这样使用

SELECT 
  id,
  CONCAT(content, 'd') content
FROM tablename;

You can also specify a WHEREclause to determine which rows to update. Something like:

您还可以指定一个WHERE子句来确定要更新哪些行。就像是:

SELECT 
  id,
  CONCAT(content, 'd') content
FROM tablename
WHERE id = 1;