How to Split a Column into Multiple Rows

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 如何将列切分成多行

| username: TiDBer_ELDgsoWY

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
| username: tidb菜鸟一只 | Original post link

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

| username: TiDBer_ELDgsoWY | Original post link

Confirmed that it is feasible. Thank you.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.