Home > Database > Mysql Tutorial > body text

How to convert one row into multiple rows in mysql

coldplay.xixi
Release: 2020-09-28 11:04:48
Original
8363 people have browsed it

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)
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template