题解 | #浙大不同难度题目的正确率#
浙大不同难度题目的正确率
https://www.nowcoder.com/practice/d8a4f7b1ded04948b5435a45f03ead8c
SELECT q1.difficult_level, SUM( CASE WHEN q.result = 'right' THEN 1 ELSE 0 END ) / COUNT(q.question_id) AS correct_rate FROM user_profile AS u JOIN question_practice_detail AS q ON u.device_id = q.device_id AND u.university = '浙江大学' JOIN question_detail AS q1 ON q.question_id = q1.question_id GROUP BY q1.difficult_level ORDER BY correct_rate ASC;
在SQL查询中,只能有一个GROUP BY
子句。
GROUP BY correct_rate
是无效的,因为你已经在计算正确率,而正确率是聚合结果,不能直接在GROUP BY
中再次引用。
不要忘了还有ORDER BY这个函数