select (case
when age>=25 then '25岁及以上'
when age>=0 and age<25 or age is NULL then '25岁以下'
end
) as age_cut,
count(*) as number
from `user_profile`
group by age_cut
select up.age_cut,count(*) as number
from (
select (case
when age>=25 then '25岁及以上'
when age>=0 and age<25 or age is NULL then '25岁以下'
end
) as age_cut
from `user_profile`
) as up
group by up.age_cut
条件表达式
case
when condition then result1 else result2
end
可与聚合函数使用,实现更加复杂的统计功能:



京公网安备 11010502036488号