使用CONCAT函数更新mysql字段? [英] update mysql field using CONCAT function?
本文介绍了使用CONCAT函数更新mysql字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个简单的查询,使用其值更新mysql字段并进行一些修改,例如,如果字段具有值(3,4,5)我可以添加(,6),以防万一它具有值并且其值为NULL然后使用,"更新字段
i need a simple query which update mysql field with its value and some modification for example if field have value (3,4,5) i can add (,6) and this just in case it have value and if its NULL then update the field with the ","
我在网上搜索并找到了称为CONCAT的mysql函数,它返回了将参数串联而成的字符串.
i searched web and find mysql function called CONCAT and it Returns the string that results from concatenating the arguments.
我尝试了这个,但这没用
i tried this one but this didn't work
UPDATE groups SET SubsID = CONCAT(SubsID,",5") WHERE GroupID = 2
它不返回任何问题,但0行受影响且字段未更新
it return no issue but 0 rows affected and field not updated
推荐答案
UPDATE GROUPS
SET SubsID = CASE WHEN SubsID IS NULL THEN '6'
ELSE CONCAT(SubsID, ',6')
END
WHERE GroupID = 2
这篇关于使用CONCAT函数更新mysql字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文