如何将逗号分隔开的字符串,拆分成多行

CREATE TABLE USER (NAME VARCHAR(200));

INSERT INTO USER(NAME) VALUES(‘张三,李四,王五’);

SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(a.name,‘,’,b.help_topic_id+1),‘,’,-1) AS NAME
FROM USER a,(SELECT 0 help_topic_id UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3) b
WHERE b.help_topic_id < (LENGTH(a.name)-LENGTH(REPLACE(a.name,‘,’,‘’))+1);

1 个赞