Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: 如何将列切分成多行
How to split a column into multiple rows in TiDB? I rewrote the SQL based on MySQL help_topic, but I didn’t get the result I wanted.
select substring_index(substring_index('Human, Animal', ',', b.help_topic_id + 1), ',', -1)
from mysql.help_topic as b
CREATE TABLE USER (NAME VARCHAR(200));
INSERT INTO USER(NAME) VALUES(‘Zhang San, Li Si, Wang Wu’);
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);
Confirmed that it is feasible. Thank you.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.