题解 23 | #统计每个学校各难度的用户平均刷题数#

【分类】:连接查询、多表连接from、join

分析思路

一开始打算使用avg(),但是涉及到不同用户,实现不了,所以只能用除法

  • 分子: 每个学校 答题数量
  • 分母: 每个学校 不同答题用户
select 查询结果 [学校;题目困难程度;平均答题数]
from 从哪张表中查询数据[多个join连接的表]
group by 分组条件 [学校;题目困难程度]

扩展

前往查看:****************************************

求解代码

方法一:

表 join 表 on 连接条件

#每个题答题的总数,要知道答题的用户有几个
select
    university,
    difficult_level,
    count(a.device_id)/count(distinct(a.device_id)) as avg_answer_cnt
from user_profile a
join question_practice_detail b on a.device_id = b.device_id
join question_detail c on b.question_id = c.question_id
group by university, difficult_level

方法二

from表连接

#每个题答题的总数,要知道答题的用户有几个
select
    university,
    difficult_level,
    count(a.device_id)/count(distinct(a.device_id)) as avg_answer_cnt
from user_profile a, question_practice_detail b, question_detail c
where a.device_id = b.device_id
and b.question_id = c.question_id
group by university, difficult_level
全部评论

相关推荐

10-14 21:00
门头沟学院 Java
吃花椒的狸猫:这个人说的倒是实话,特别是小公司,一个实习生哪里来的那么多要求
点赞 评论 收藏
分享
牛客83265014...:完了,连现在都没开始面,13号投的是不是晚了
秋招的第一个offer,...
点赞 评论 收藏
分享
评论
1
1
分享

创作者周榜

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