题解 | #统计每个用户的平均刷题数#
统计每个用户的平均刷题数
http://www.nowcoder.com/practice/f4714f7529404679b7f8909c96299ac4
select
u.university,
qd.difficult_level,
round(count(qp.question_id)/count(distinct(u.device_id)), 4) avg_answer_cnt
from user_profile u
join question_practice_detail qp on qp.device_id = u.device_id
join question_detail qd on qp.question_id = qd.question_id
group by u.university, qd.difficult_level
having u.university = "山东大学"
在join的位置最好使用inner join