select 临时表+group by+case when

分群并计算群体人数

https://www.nowcoder.com/practice/24319fd5c03e482c935783107114933d

select age_group,count(age_group) as user_count
from
    (
        select
            case
                when age < 20 then '20以下'
                when age >= 20
                and age <= 50 then '20-50'
                when age > 50 then '50以上'
                when age is null then '未填写'
            end as age_group
        from
            customers_info
    ) as test
group by age_group    

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务