mysql把一字段拆分为多行

sql语句

select a.house_no as '房子',substring_index(substring_index(a.name,',',b.help_topic_id+1),',',-1) as '拥有者' 
from  aa a
join   mysql.help_topic b on b.help_topic_id < (length(a.name) - length(replace(a.name,',',''))+1);

 

关键点
mysql.help_topic b on b.help_topic_id < (length(a.name) - length(replace(a.name,',',''))+1)

name格式:张三,李四,王五

posted @ 2019-02-15 11:30  zhangkui  阅读(6905)  评论(0编辑  收藏  举报