数据库中数据存储形式
需求:根据字符串中用","隔开的数据分组
select
SUBSTRING_INDEX( SUBSTRING_INDEX( base.key_personnel_type, ',', top.help_topic_id + 1 ), ',',- 1 ) AS keyPersonType,
count(1) as keyPersonCount
from
sp_base_info_populace base
LEFT JOIN mysql.help_topic as top on top.help_topic_id < (length( base.key_personnel_type)- length(REPLACE (base.key_personnel_type ,',', '' ))+1)
where
base.is_deleted =0
group by
keyPersonType
结果: