mysql分割字符串

2018-08-02 17:22:59

Mysql mysql

数据库当前信息为: 1

将a,b分割开,变成两条数据 2

SQL:

SELECT a.id,SUBSTRING_INDEX(SUBSTRING_INDEX(a.`name`,',',b.help_topic_id+1),',',-1) as `name`  
from a a left join mysql.help_topic b 
on b.help_topic_id < (LENGTH(a.`name`)-LENGTH(REPLACE(a.`name`,',',''))+1) 

ORDER BY a.id;   

SQL是使用了mysql提供的SUBSTRING_INDEX函数

摘自b229911288的博客