分别查询两个条件,用union合并查询结果。符合when条件的记为1,不符合条件的记为0,对判断结果进行sum求和。

select
    '25岁以下' as age_cut,
    sum(case when age < 25 or age is null then 1 else 0 end) number
from
    user_profile
union
select
    '25岁及以上' as age_cut,
    sum(case when age >= 25 then 1 else 0 end) number
from
    user_profile;