题解 | #统计每个学校各难度的用户平均刷题数#
统计每个学校各难度的用户平均刷题数
https://www.nowcoder.com/practice/5400df085a034f88b2e17941ab338ee8
select university, difficult_level, round( count(qpd.question_id) / count(distinct qpd.device_id), 4 ) as avg_answer_cnt from question_practice_detail as qpd left join user_profile as up on up.device_id = qpd.device_id left join question_detail as qd on qd.question_id = qpd.question_id group by university, difficult_level
注意left join的使用,主要根据基表进行连接。因为题目中说“答题”的人,因此使用left join时需要以用户答题“题库练习明细表:question_practice_detail”为基表进行连接,即该表表示哪个用户答哪道题。