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

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

select 
    # 这里用distinct 排除重复device_id情况
    count(distinct device_id) as male_num,
    avg(gpa) as avg_gpa
from user_profile
group by gender
having gender='male'
这里说下两种解法吧
  1. select
      count(gender) as male_num,
      round(avg(gpa), 1) as avg_gpa
    from user_profile where gender="male";
    一般是建议直接用group by 然后 having, 这样的效率会略高
全部评论

相关推荐

06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-02 18:35
简历上把1个月实习写成了3个月,会进行背调吗?
码农索隆:一个月有一个月的实习经历,三个月有三个月的实习经历
点赞 评论 收藏
分享
评论
3
3
分享

创作者周榜

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