题解 | #统计每个学校的答过题的用户的平均答题数#

统计每个学校的答过题的用户的平均答题数

https://www.nowcoder.com/practice/88aa923a9a674253b861a8fa56bac8e5

联结查询

想知道每个学校的答过题的用户的平均答题数,需要先知道每个学校的总答题数和总用户数,一除就是平均答题数。

COUNT(question_id) 和 COUNT(DISTINCT device_id)实现上述两个参数

如何实现联结查询?两种写法:

  1. 通过where子句联结外键
  2. 通过 A inner join B on A.xx = B.xx

最终答案(inner join写法):

select university, ROUND(count(question_id)/count(distinct user_profile.device_id), 4)

from question_practice_detail inner join user_profile

on user_profile.device_id = question_practice_detail.device_id

group by university

order by university;

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 11:29
点赞 评论 收藏
分享
06-07 19:59
门头沟学院 C++
补药卡我啊😭:都快15年前的了还在11新特性
你的简历改到第几版了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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