题解 | #浙大不同难度题目的正确率#
浙大不同难度题目的正确率
https://www.nowcoder.com/practice/d8a4f7b1ded04948b5435a45f03ead8c
select difficult_level, avg(case when qpd.result='right' then 1 else 0 end) as correct_rate # 对result进行统计平均数,如果result为right则记作1,否则记为0,这样就可以用AVG函数来统计正确率 # 为了防止结果中有难度为None的结果,需要在order by前加一句 having qd.difficult_level != 'None' from user_profile up left join question_practice_detail qpd on up.device_id=qpd.device_id left join question_detail qd on qpd.question_id=qd.question_id # 利用相同键将三个表连接起来 where university='浙江大学' # 浙江大学的学生 group by difficult_level # 按难度分组 having qd.difficult_level != 'None' # 为了防止因为左连接导致可能存在部分difficult_level为空的情况,需要把空的difficu_level去掉 order by correct_rate;