编程技术

mysql一行变成多行的方法:1、将一行变成多行,代码为【substring_index(substring_index( a.rn,’,’,b.help_topic_id + 1 ),’,’ ,- 1)】;2、将多列变成多行。

mysql如何将一行变成多行_编程技术_编程开发技术教程插图

mysql将一行变成多行的方法:

44c937c8cb0c09476feb5eb1491e43b.png

转成

319e6ba2e18fdb554f76d45f15250a0.png

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

19275fe886e86f672f00b79d7057937.png

图a

6f3e1d38d92ed1e69418732db8a3097.png

图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)

mysql如何将一行变成多行
—–文章转载自PHP中文网如有侵权请联系admin#tyuanma.cn删除

如何彻底删除multisim

云服务器推荐