题解 | 计算男生人数以及平均GPA

计算男生人数以及平均GPA

https://www.nowcoder.com/practice/7d9a7b2d6b4241dbb5e5066d7549ca01

# 解法一(常规思路)
select
    count(1) as male_num,
    round(avg(gpa), 1) as avg_gpa
from
    user_profile
where
    gender = 'male';

# 解法二(条件聚合)
select
    count(case when gender= 'male' then 1 else null end) as male_num,
    round(avg(case when gender= 'male' then gpa else null end), 1) as avg_gpa
from
    user_profile;

全部评论

相关推荐

挥毫自在:想白嫖你呢
点赞 评论 收藏
分享
92Y:泡成巨人观了吧
投递百度等公司10个岗位
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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