题解 | #统计每个用户的平均刷题数#
统计每个用户的平均刷题数
https://www.nowcoder.com/practice/f4714f7529404679b7f8909c96299ac4
select s1.university, s3.difficult_level, round(count(s2.question_id)/count(distinct s2.device_id),4) as avg_answer_cnt from user_profile as s1 inner join question_practice_detail as s2 on s1.device_id = s2.device_id and s1.university='山东大学' inner join question_detail as s3 on s2.question_id = s3.question_id group by s3.difficult_level,s1.university; select "山东大学" as university, difficult_level, count(qpd.question_id) / count(distinct qpd.device_id) as avg_answer_cnt from question_practice_detail as qpd inner join user_profile as up on up.device_id=qpd.device_id and up.university="山东大学" inner join question_detail as qd on qd.question_id=qpd.question_id group by difficult_level /* group by 后要排序n-1个字段,不排序则须如method2 将university设置成同一content */