Mysql数据处理-字段是带分隔符的数组

141 阅读1分钟

如:将前表uid更新为后表的newid(之前关联关系为a.uid=b.id)

image.png

image.png sql:

UPDATE mytask a INNER JOIN (SELECT id,GROUP_CONCAT(newid SEPARATOR ',') newid FROM (SELECT a.id,a.uid,b.newid FROM (select a.id,substring_index(substring_index(a.uid, ',', b.help_topic_id + 1), ',', -1) uid from mytask a JOIN mysql.help_topic b ON b.help_topic_id < (length(a.uid) - length(REPLACE(a.uid, ',', '')) + 1) ) a INNER JOIN myuser b on a.uid=b.id) a GROUP BY id) b on a.id=b.id SET a.uid=b.newid;

注意 GROUP_CONCAT函数需要和GROUP BY配合使用

执行结果

image.png