gpt4 book ai didi

mysql - SQL 更新 - 将字符串添加到一个属性

转载 作者:行者123 更新时间:2023-11-29 14:47:53 25 4
gpt4 key购买 nike

我的 mysql 表是:产品(名称、价格、元描述)

我想编写一个 SQL UPDATE 来设置我的元描述名称+'仅适用于'+metaDescription

我尝试过,但没有成功

UPDATE 
product
SET
metaDescription=name+' is just for'+price;

最佳答案

您应该使用concat function :

update product
set metaDescription = concat(name, ' is just for ', price);

MySQL 应该自动为您将 price 转换为字符串类型。

当您使用 + 时,MySQL 正在尝试将您的字符串转换为数字(并且默默地失败):

mysql> select 'this' + 'that';
+-----------------+
| 'this' + 'that' |
+-----------------+
| 0 |
+-----------------+

关于mysql - SQL 更新 - 将字符串添加到一个属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6490423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com