题解 | #统计每个学校的答过题的用户的平均答题数#
统计每个学校的答过题的用户的平均答题数
http://www.nowcoder.com/practice/88aa923a9a674253b861a8fa56bac8e5
select university,
count(question_id) / count(distinct question_practice_detail.device_id) as avg_answer_cnt
from user_profile
inner join question_practice_detail
on user_profile.device_id = question_practice_detail.device_id
group by university
- 外连接:inner join 只显示有效数据
- 每个学校:group by university
- 平均答题数 = 总答题数 / 总人数