我的表格结构如下,

ID  Name    Source
1   John    first.jpg
2   Doe second.jpg
3   Mary    third.jpg
4   Kurian  four.jpg

我想更新“Source”,在前面加上主机和主键,如下所示
http://example.com/1/first.jpg
http://example.com/2/second.jpg
http://example.com/3/third.jpg
http://example.com/4/four.jpg

尝试使用CONCAT(“http://example.com/”+id,Source),但失败,截断的双精度值不正确:
任何建议都将受到极大的重视。

最佳答案

尝试

UPDATE table_name
SET Source = CONCAT('http://example.com/', ID, '/', Source);

结果
| ID |   Name |          Source                 |
|----|--------|---------------------------------|
|  1 |   john |  http://example.com/1/first.jpg |
|  2 |    Doe | http://example.com/2/second.jpg |
|  3 |   Mary |  http://example.com/3/third.jpg |
|  4 | Kurian | http://example.com/4/fourth.jpg |

关于mysql - MySQL查询将前缀前缀为字段中的现有值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48476269/

10-12 17:04
查看更多