题解 | 统计每个学校的答过题的用户的平均答题数
统计每个学校的答过题的用户的平均答题数
https://www.nowcoder.com/practice/88aa923a9a674253b861a8fa56bac8e5
select university, round(sum(cnt)/count(id),4) as avg_answer_cnt from (select device_id as id, count(question_id) as cnt from question_practice_detail group by id) temp left join user_profile on temp.id=user_profile.device_id group by university order by university
二次聚合,先算每名同学做了多少题,再算每所学校的同学平均做了多少题,一开始临时表没起名字报错没看懂,一看答案发现还能直接一次聚合的