MySQL string of substrings divided into rows & Statistics

Help_topic string conversion table using the row (delimiter ',' )

 

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

 

Statistical substring occurrences of each string (delimiter ',' )

 

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

Guess you like

Origin www.cnblogs.com/cmnull/p/11127219.html
Recommended