计算mysql中某个字段某字符出现的次数,case when 和 截取字符的用法

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'

上一篇:Java才是世界上最好的语言,Java在高频交易中替代C++


下一篇:Android中方便好用的倒计时类