题解 | #操作符混合运用#
统计每个用户的平均刷题数
http://www.nowcoder.com/practice/f4714f7529404679b7f8909c96299ac4
考点1 多表链接:
#多表链接:连用两个join
question_practice_detail qp LEFT JOIN user_profile u ON
qp.device_id = u.device_id
left join question_detail q on
qp.question_id = q.question_id
考点2 分组:
#分组 group by
不同难度下即
group by difficult_level
考点3 限定条件:
where university = '山东大学'
考点4 小数电点保留四位
#round函数
round(COUNT(qp.question_id)/ count(DISTINCT qp.device_id),4)
完整答案:
select university,
difficult_level,
round(COUNT(qp.question_id)/ count(DISTINCT qp.device_id),4) AS avg_answer_cnt
FROM
question_practice_detail qp LEFT JOIN user_profile u ON
qp.device_id = u.device_id
left join question_detail q on
qp.question_id = q.question_id
where university = '山东大学'
group by difficult_level