我需要执行以下操作,并且正在为语法苦苦挣扎:
我有一个名为“mytable”的表和一个名为“mycolumn”(字符串)的列。
在 mycolumn 中,该值是一个构造值 - 例如,其中一个值是:'first:10:second:18:third:31'。mycolumn 中的值都使用相同的模式,只是 ids/numbers 不同。
我需要将 18 的值(在这种特殊情况下)更改为来自另一个表键的值。此列值的最终结果应该是“first:10:second:22:third:31”,因为我将 18 替换为 22。我使用 18 作为查找值从另一个表中获得了 22。
因此,理想情况下,我将拥有以下内容:
UPDATE mytable
SET mycolumn = [some regex function to find the number between 'second:' and ":third" -
let's call that oldkey - and replace it with other id from another table -
(select otherid from tableb where id = oldkey)].
我知道 mysql 有一个 REPLACE 功能,但这还不够。