列转多行---Mysql

数据准备:

CREATE TABLE   test   (  num varchar(100), score varchar(100)   );

INSERT INTO test(num, score)  VALUES('1', '2,5,4');
INSERT INTO test(num, score)  VALUES('2', '4');
INSERT INTO test(num, score)  VALUES('3', '2,5,5,3,4');

原始:

 

 

列转多行:

select SUBSTRING_INDEX(SUBSTRING_INDEX(score , ',' , b.help_topic_id+1 ) , ',' , -1)
from test  a
join mysql.help_topic b
on b.help_topic_id<LENGTH(a.score)-LENGTH(REPLACE(a.score, ',' ,''))+1

 结果:

 

posted @ 2021-06-22 17:49  jiujiujiujiujiujiu  阅读(180)  评论(0)    收藏  举报