Home  >  Article  >  Database  >  How to convert one row into multiple rows in mysql

How to convert one row into multiple rows in mysql

coldplay.xixi
coldplay.xixiOriginal
2020-09-28 11:04:488258browse

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.

How to convert one row into multiple rows in mysql

Mysql method to turn one row into multiple rows:

Put

How to convert one row into multiple rows in mysql

Convert to

How to convert one row into multiple rows in 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, &#39;,&#39;, &#39;&#39;)  ) + 1)

Convert Picture A to Picture B

How to convert one row into multiple rows in mysql

Picture a

How to convert one row into multiple rows in mysql

图b

SELECT
    substring_index(substring_index( a.rn,&#39;,&#39;,b.help_topic_id + 1    ),  &#39;,&#39; ,- 1    ) AS rn
FROM
    (select SUBSTR(GROUP_CONCAT( REPEAT(CONCAT(number,&#39;,&#39;),fre) SEPARATOR &#39;&#39;),1,LENGTH(GROUP_CONCAT( REPEAT(CONCAT(number,&#39;,&#39;),fre) SEPARATOR &#39;&#39;))-1) as rn  from numbers ) a  
JOIN mysql.help_topic b ON b.help_topic_id <
(length(a.rn) - length( replace(a.rn, &#39;,&#39;, &#39;&#39;)  ) + 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn