Mysql 字符串拆分 OR 一行转多行
需要了解的的几个mysql 函数:
A.substring_index():字符串截取 substring_index(str,delim,count)
str:要处理的字符串
delim:分隔符
count:计数
B.length():字符长度函数
C.replace():替换函数
不说了,直接看代码:
SELECT substring_index(substring_index( a.chain,\'_\',b.help_topic_id + 1 ), \'_\' ,- 1 ) AS ID FROM (select \'1_11_1223_1242\' as chain) a JOIN mysql.help_topic b ON b.help_topic_id < (length(a.chain) - length( replace(a.chain, \'_\', \'\') ) + 1)
结果