条件函数if、case when 表达式 then、case 表达式 when then

case when 表达式 then 写法

select case when age<25 or age is null then "25岁以下"

when age>=25 then "25岁及以上"

end age_cut,

count(*) number

from user_profile

group by age_cut

if 条件写法

select if(age<25 or age is null,"25岁以下","25岁及以上") age_cut, count(*) number from user_profile group by age_cut