select LENGTH(type) - LENGTH(replace(type,'_','')) as counts from sa_log_olap where type like 'XX_XXXX_%'
CASE WHEN LENGTH(type) - LENGTH(replace(type,'_',''))=2 THEN 'parent'
WHEN LENGTH(type) - LENGTH(replace(type,'_',''))=3 and SUBSTRING_INDEX(replace(type,concat(concat('XX_',#{name}),'_'),''),'_',1)!=''
THEN SUBSTRING_INDEX(replace(type,concat(concat('XX_',#{name}),'_'),''),'_',1)
WHEN LENGTH(type) - LENGTH(replace(type,'_',''))=3 and SUBSTRING_INDEX(replace(type,concat(concat('XX_',#{name}),'_'),''),'_',1)=''
THEN 'parent'