题解 | #统计每个用户的平均刷题数#

统计每个用户的平均刷题数

https://www.nowcoder.com/practice/f4714f7529404679b7f8909c96299ac4

select
  a.university,
  c.difficult_level,          --------------------------------------------第五步,由于第四步进行分组,所以select需回应group by条件
  round(
    count(b.question_id) / count(distinct b.device_id),    
    4
  ) as avg_answer_cnt     ---------------第六步,由题意知道,平均答题题目数=count(b.question_id) / count(distinct b.device_id),结果保留4位小数【这步是此题的关键点,需要多读题,自行理解怎么得到平均答题题目数
from
  (
    select
      device_id,
      university
    from
      user_profile
    where
      university = '山东大学'
  ) a                        ---------------------------第一步,先条件求出‘山东大学’
  join question_practice_detail b on a.device_id = b.device_id          ----------------------第二步,a表 jion b表,关联条件device_id
  join question_detail c on b.question_id = c.question_id             --------------------------第三步,b表 jion c表,关联条件question_id 
group by
  a.university,
  c.difficult_level;                ---------------------------------------------------------------------------------第四步,根据题目要求,对university和difficult_level进行分组
#MySQL#
全部评论

相关推荐

05-29 09:02
门头沟学院 Java
点赞 评论 收藏
分享
06-15 18:44
黄淮学院 Java
Lynn012:如果是居民楼还是算了吧,看着有点野呢
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 11:47
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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