select (case when age<25 or age is null then '25岁以下' else '25岁及以上' end) as age_cut,
count(distinct device_id) as number
from user_profile
group by age_cut;

需要和分组函数配合使用的聚合函数及其别名不能使用在group by () 语句中。

但是,窗口函数及其别名可以再次运用到分组函数中。