欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

MySQL 字符串分隔成行&子串统计

程序员文章站 2022-09-27 19:47:47
利用help_topic表把字符串转换成行(分隔符号',') 统计字符串每个子串出现次数(分隔符号',') ......

利用help_topic表把字符串转换成行(分隔符号',')

 

select substring_index(substring_index('a,b,c,d,e,f,g,h',',',`help_topic_id`+1),',',-1) as `id` from mysql.`help_topic`;

 

统计字符串每个子串出现次数(分隔符号',')

 

select substring_index(substring_index(a.`column`,',',b.`help_topic_id` + 1),',',-1) as `sub_column`,count(a.`column`) as `count`
from `test` a
join mysql.`help_topic` b on b.`help_topic_id` < (length(a.`column`) - length(replace(a.`column`,',',''))+1)
group by substring_index(substring_index(a.`column`,',',b.`help_topic_id` + 1),',',-1);