我正在寻找一种方法,通过MySQL查询将一部分字符串替换为同一行的字符串的一部分。
例如,如果我有title ='blablabla - XX.YY.ZZZZ'的记录,我想只将字符串ZZZZ添加到字段 - extra_fields,但格式为'[{“value”:“ ZZZZ“}]'
原始表:
title | extra_field
--------------------
19.02.1996 | [empty]
13.05.1815 | [empty]
22.03.2016 | [empty]
更新后我需要:
title | extra_field
-------------------
19.02.1996 | Year was 1996
13.05.1815 | Year was 1815
22.03.2016 | Year was 2016
答案 0 :(得分:0)
查询解决方案
UPDATE yourtable SET extra_field = CONCAT('Year was ', SUBSTRING(title,7))
或
UPDATE yourtable SET extra_field = CONCAT('Year was ', SUBSTRING(title,-4))