MySQL的更新数据追加到列 [英] MySQL UPDATE append data into column

查看:301
本文介绍了MySQL的更新数据追加到列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新的表名(col1name)

I need to UPDATE tablename (col1name)

如果已经存在的数据,我需要与价值观A,B,C'追加它
如果是空的,我需要添加值A,B,C

If there is already data, I need to append it with values 'a,b,c' If it is NULL, I need to add the values 'a,b,c'

我知道有一个说法CONCAT,但不能确定SQL语法是什么。

I know there is a CONCAT argument, but not sure what the SQL syntax would be.

更新的tablename集col1name = CONCAT(IFNULL(col1name,A,B,C'),'A,B,C')

就是上面是否正确?

推荐答案

尝试此查询:

update tablename set col1name = concat(ifnull(col1name,""), 'a,b,c');

请参阅此SQL小提琴演示。

这篇关于MySQL的更新数据追加到列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆