sql拆分逗号分隔的字段,并统计

sql拆分逗号分隔的字段,并统计_第1张图片
select name ,count(*) from (SELECT moe.id,substring_index( substring_index( moe.options, ',', b.help_topic_id + 1 ), ',',- 1 ) name
FROM t_questionnaire_record moe
JOIN mysql.help_topic b ON b.help_topic_id < ( length( moe.options ) - length( REPLACE ( moe.options, ',', '' ) ) + 1 ) 
order by moe.id
) abc
group by name
sql拆分逗号分隔的字段,并统计_第2张图片

open_id为唯一id,其中options存储open_id参与过的所有option_id,图二中name表示option_id,count(*)表示option_id下总参与数。

你可能感兴趣的:(sql)