MYSQL-另一种行转列的实现方式
行转列的实现方式:使用mysql.help_topic
--行转列 SELECT b.help_topic_id, substring_index( a.levels, ',', b.help_topic_id +1 ), substring_index( substring_index( a.levels, ',', b.help_topic_id+1 ), ',',- 1 ) AS level FROM ( select '1,2,3,4' as levels from mysql.db limit 1 ) a JOIN mysql.help_topic b ON b.help_topic_id < ( length( a.levels ) - length( REPLACE ( a.levels, ',', '' ) ) +1 )
演示效果
(1)转换前
select '1,2,3,4' as levels from mysql.db limit 1 ;
(2)转换后
本文来自博客园,作者:业余砖家,转载请注明原文链接:https://www.cnblogs.com/yeyuzhuanjia/p/17261915.html