1.case...when...then...else...end...
示例:
select
case when profile like '%,male' then 'male'
when profile like '%female' then 'female'
end gender, count(device_id) number
from user_submit
group by gender;
用法:
case
when boolean表达式 then 分类的名字
when boolean表达式 then 分类的名字
...
else 分类的名字
end 列的名字
2.substring_index(a, b, c)
示例:
SELECT SUBSTRING_INDEX(profile,",",-1) gender,COUNT(*) number
FROM user_submit
GROUP BY gender;
用法:
a代表你要分割的字段
b代表你用什么来分割,(注意加双引号)
c代表你要取分割之后的哪一段,从左向右是从1开始,从右向左是-1开始。
用于要分割并显示的字段
3.if(布尔表达式, 满足条件要做的, 不满足条件要做的)
示例:
SELECT IF(profile LIKE '%female','female','male') gender,COUNT(*) number
FROM user_submit
GROUP BY gender;