MySQL 根据字段中的逗号分隔成多条数据

 将数据库表的字段进行切割,分成多条数据。

表数据:

test表

编辑

期望得到的查询结果为:

id                  name

1                   张三

1                   李四

1                   王五

2                   肖1

2                   肖2

sql语句:

select a.id,substring_index(substring_index(a.name,',',b.help_topic_id+1),',',-1) name 
from test a join
mysql.help_topic b
on b.help_topic_id < (length(a.name) - length(replace(a.name,',',''))+1)
order by a.id;
posted @ 2022-09-16 14:33  小牛同学丶  阅读(2376)  评论(3编辑  收藏  举报