mysql 切割字符串,实现一行变多行

时间:2021-01-20 11:44:32   收藏:0   阅读:0

mysql.help_topic 

利用help_topic表把以逗号分隔的字符串转换成行。

SELECT
    substring_index(substring_index( a.rn,‘,‘,b.help_topic_id + 1    ),‘,‘ ,- 1) AS rn
FROM
    (select ‘1,2,3,4‘ as rn) a  
JOIN mysql.help_topic b ON b.help_topic_id <
(length(a.rn) - length( replace(a.rn, ‘,‘, ‘‘)  ) + 1)

效果如下

技术图片

 详细实现思路可以看下这个https://blog.csdn.net/zhxdick/article/details/105531916

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!