当前位置: 移动技术网 > IT编程>数据库>Mysql > MySQL 字符串分隔成行&子串统计

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

2019年07月04日  | 移动技术网IT编程  | 我要评论

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网