mysql查询包含特定符号的数据,并拆分为多行显示

需求描述:字段中包含有逗号隔开的多个id数据组合,需要将每个数据id拆分单独作为一条记录插入至另一个表中,如下:

 

sql语句,如下:

select substring_index(substring_index(a.access_code,',',b.help_topic_id+1),',',-1) as access_code
from frame_menu a
join mysql.help_topic b on b.help_topic_id<(length(a.access_code)-length(replace(a.access_code,',',''))+1)

执行结果,如下:

 

posted @ 2019-05-28 15:16  东半球的王小白  阅读(1035)  评论(0)    收藏  举报