select 
case
when age is null OR age < 25 then '25岁以下'
when age >= 25 then '25岁及以上'
end as age_cut, count(ifnull(age,0)) 
from user_profile
group by age_cut

使用case语句来判断age属于什么类别,示例:

CASE WHEN 条件1 THEN 结果1 WHEN 条件2 THEN 结果2 ... ELSE 默认结果 END

这里注意计算数量时,count()函数不会统计null值,因此将age为null的情况指定为0,十四号用ifnull()进行判断

分组则是通过年龄的类型,