Mysql单行字段拆分多行

SQL单行拆分多行

不需要自建自增的辅助表,Mysql自带help_topic可以使用;

SELECT SUBSTRING_INDEX( SUBSTRING_INDEX( target_column, ',', b.help_topic_id + 1 ), ',', -1 ) AS coop_branch FROM survey_draft AS a JOIN mysql.help_topic AS b ON b.help_topic_id < ( length( a.target_column ) - length( REPLACE ( a.target_column, ',', '' ) ) + 1 )

其中help_topic_id共有504个值,既是你要拆分的字段中最多包含五百个逗号,在mysql5.7版本help_topic已经增加到661个。

原文地址:https://www.cnblogs.com/mzc1997/p/13177658.html