题解 | #分群并计算群体人数#

分群并计算群体人数

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

select age_group, user_count
from 
(
select (case when age < 20 then '20以下' end) age_group,
    sum(case when age < 20 then 1 else 0 end) user_count,
    4 'r'
from customers_info
group by age_group

union
select (case when age > 50 then '50以上' end) age_group,
    sum(case when age > 50 then 1 else 0 end) user_count,
    2 'r'
from customers_info
group by age_group

union
select (case when age is null then '未填写'end) age_group,
    sum(case when age is null then 1 else 0 end) user_count,
     3 'r'
from customers_info
group by age_group

union
select (case when age > 20 and age < 50 then '20-50' end) age_group,
    sum(case when age > 20 and age < 50 then 1 else 0 end) user_count,
    1 'r'
from customers_info
group by age_group
)t 
where age_group is not null
order by r

#             when age > 50 then '50以上'
#             when age is null then '未填写'
#             else '20-50'
#         end age_group,
# from customers_info

全部评论

相关推荐

nus2201602...:兄弟,你这个简历撕了丢了吧,就是一坨,去找几个项目,理解项目流程,看几遍就是你的了,看看八股就去干了,多看看牛客里别人发出来的简历,对着写,你这写的啥啊,纯一坨
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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