使用到数据库自带的mysql.help_topic表来属性拆分,help_topic表就是实现行转列功能
select substring_index( substring_index('1,2,3,4,5',',',help_topic_id + 1),',' ,- 1) test from mysql.help_topic where help_topic_id < (length('1,2,3,4,5')) - length(replace ('1,2,3,4,5', ',', '')) + 1;
substring_index(‘1,2,3,4,5’,‘,’,help_topic_id + 1)作用:
层级输出(‘10,21,13,34,15’)如下所示:
substring_index(substring_index(‘10,21,13,34,15’,‘,’,help_topic_id + 1),‘,’ ,- 1)作用:
参数-1取最后一个值,示例如下:
(length(‘10,21,13,34,15’))作用:
计算字符串总长度
length(replace (‘10,21,13,34,15’, ‘,’, ‘’))作用:
计算去除逗号的长度:
(length(‘10,21,13,34,15’)) - length(replace (‘10,21,13,34,15’, ‘,’, ‘’)) + 1作用:
两者相减,计算出逗号分隔的字符串数量
到此这篇关于mysql使用mysql.help_topic表实现一行转多行的实现示例的文章就介绍到这了,更多相关mysql mysql.help_topic表一行转多行内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论