题解 | #统计每个用户的平均刷题数#
统计每个用户的平均刷题数
http://www.nowcoder.com/practice/f4714f7529404679b7f8909c96299ac4
读懂题目的隐含意,分组包含了学校分组和难度分组,最后使用having分组
select
university,
difficult_level,
count(qpd.question_id) / count(distinct qpd.device_id)
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 difficult_level, university
having university = '山东大学'