题解 | #统计每个学校各难度的用户平均刷题数#
统计每个学校各难度的用户平均刷题数
http://www.nowcoder.com/practice/5400df085a034f88b2e17941ab338ee8
问题分解: 1.每个学校:按学校分组 group by university 2.不同难度:按难度分组 group by difficult_level 3.平均答题量分组后count(*)/(count(distinct(u.device_id)))
解题: 1.可先将题库信息明细表(question_practice_detail)和题难度表(question_detail)放在一起组成一个新的答题细节表q
SELECT p.*,difficult_level FROM
question_detail d,question_practice_detail p
where d.question_id=p.question_id
3.将新的细节表与用户信息表结合一起,进行分组查询,
select university,difficult_level,count(*)/(count(distinct(u.device_id))) avg_answer_cnt from
(SELECT p.*,difficult_level FROM
question_detail d,question_practice_detail p
where d.question_id=p.question_id) q
join user_profile u
on u.device_id=q.device_id
group by university,difficult_level