题解 | #统计每个用户的平均刷题数#
统计每个用户的平均刷题数
http://www.nowcoder.com/practice/f4714f7529404679b7f8909c96299ac4
SELECT
up.university,
qd.difficult_level,
COUNT(qpd.question_id)/ COUNT(DISTINCT qpd.device_id) AS avg_answer_cnt
FROM
question_practice_detail as qpd
LEFT JOIN
user_profile as up on up.device_id = qpd.device_id
INNER JOIN
question_detail AS qd ON qpd.question_id = qd.question_id
WHERE
up.university = "山东大学"
GROUP BY
difficult_level
;
up.university,
qd.difficult_level,
COUNT(qpd.question_id)/ COUNT(DISTINCT qpd.device_id) AS avg_answer_cnt
FROM
question_practice_detail as qpd
LEFT JOIN
user_profile as up on up.device_id = qpd.device_id
INNER JOIN
question_detail AS qd ON qpd.question_id = qd.question_id
WHERE
up.university = "山东大学"
GROUP BY
difficult_level
;