Mysql method to turn one line into multiple lines: 1. To turn one line into multiple lines, the code is [substring_index(substring_index( a.rn,',',b.help_topic_id 1 ),',', - 1)]; 2. Convert multiple columns into multiple rows.
Mysql method to turn one row into multiple rows:
Put
Convert to
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)
Convert Picture A to Picture B
Picture 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)
More related free learning recommendations:mysql tutorial(video)
The above is the detailed content of How to convert one row into multiple rows in mysql. For more information, please follow other related articles on the PHP Chinese website!