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

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

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

题目 :参加了答题的山东大学的用户在不同难度下的平均答题题目数

分析思路:
1.分组 --- 按照学校、难度分组
group by t1.university,t3.difficult_level
2.分组后的筛选 --- 山东大学
having t1.university = '山东大学';
3.三表连接,注意连接条件(采用sql99语法格式)
user_profile t1 join question_practice_detail t2
on t1.device_id = t2.device_id
join question_detail t3
on t2.question_id = t3.question_id
4.平均答题数的一个计算,每个组的总答题量/答题人数
count(*)/count(distinct t1.device_id),4)
5.round保留四位小数,起别名

解体思路:
select t1.university,t3.difficult_level,
round(count(*)/count(distinct t1.device_id),4) avg_answer_cnt
from user_profile t1 join question_practice_detail t2
on t1.device_id = t2.device_id
join question_detail t3
on t2.question_id = t3.question_id
group by t1.university,t3.difficult_level
having t1.university = '山东大学';


全部评论

相关推荐

01-17 08:34
门头沟学院 Java
想找对象的单身狗在努力存钱:这工资不低了,再高点人家要招博士硕士的
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务