clickhouse使用case when实现查询
查询年龄区间中的人数
select user.age_range as age,count(distinct user.cuid) as count
from (
select
cuid,
case
when age>='18' and age<='24' then '18-24岁'
when age>='25' and age<='29' then '25-29岁'
when age>='30' and age<='34' then '30-34岁'
when age>='35' then '35-100岁'
end as age_range
from
person
where
has(professional, 'student')
and
has(sex, '男')
) user group by age_range
查询结果:
18-24岁 100
25-29岁 50
30-34岁 20
35-100岁 0