mysql中把一行拆成多行
把 转成
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)
一张表如果保存了数据的值以及出现的频率,怎么把它转成多行
图A转成图B
图A 图B
SELECT substring_index(substring_index( a.rn,',',b.help_topic_id + 1 ), ',' ,- 1 ) AS rn FROM (select SUBSTR(GROUP_CONCAT( REPEAT(CONCAT(number,','),fre) SEPARATOR ''),1,LENGTH(GROUP_CONCAT( REPEAT(CONCAT(number,','),fre) SEPARATOR ''))-1) as rn from numbers ) a JOIN mysql.help_topic b ON b.help_topic_id < (length(a.rn) - length( replace(a.rn, ',', '') ) + 1)
作者:苏su
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.