题解 | #统计每个学校各难度的用户平均刷题数#

统计每个学校各难度的用户平均刷题数

http://www.nowcoder.com/practice/5400df085a034f88b2e17941ab338ee8

成功:连用两次内连接

SELECT university,difficult_level,round((count(qpd.result)/count(DISTINCT qpd.device_id)),4) as avg_answer_cnt
FROM user_profile as u 
INNER JOIN question_practice_detail as qpd 
ON u.device_id = qpd.device_id
INNER JOIN question_detail as qd
ON qpd.question_id = qd.question_id
GROUP BY university,difficult_level
ORDER BY university ASC,difficult_level ASC

👇错误原因:MySQL不支持WITH语句,不支持物化视图

WITH q(id,device_id,question_id,result,difficult_level) AS
    SELECT qpd.id,qpd.device_id,qpd.question_id,qpd.result,qd.difficult_level
    FROM question_practice_detail as qpd INNER JOIN question_detail as qd
    ON qpd.question_id = qd.question_id
SELECT university,difficult_level,round((count(q.result)/count(DISTINCT q.device_id)),4)avg_answer_cnt
FROM user_profile as u INNER JOIN q
ON u.device_id = q.device_id
GROUP BY university,difficult_level
ORDER BY university ASC,difficult_level ASC
全部评论

相关推荐

10-25 00:32
香梨想要offer:感觉考研以后好好学 后面能乱杀,目前这简历有点难
点赞 评论 收藏
分享
评论
2
1
分享
牛客网
牛客企业服务