题解 | #统计每个用户的平均刷题数#
统计每个用户的平均刷题数
https://www.nowcoder.com/practice/f4714f7529404679b7f8909c96299ac4
select up.university,qd.difficult_level,count(qpd.question_id)/count(distinct qpd.device_id) from user_profile as up inner join question_detail as qd inner join question_practice_detail as qpd on up.device_id = qpd.device_id and qd.question_id = qpd.question_id and up.university like "%山东%" group by qd.difficult_level;
其实就是考多表链接
有几个要注意的点:
平均答题数目就是答题的总数量/总人数(人数可能会有一个人答多题的现象,所有要用distinct去重)
因为是指定山东大学所以用了and up.university like "%山东%",这里制定了山东大学其实直接用and up.university = "山东大学"更对。
最后group by up.university,qd.difficult_level; 是按题目对题目难度进行分组