题解 | #浙大不同难度题目的正确率#
浙大不同难度题目的正确率
https://www.nowcoder.com/practice/d8a4f7b1ded04948b5435a45f03ead8c
先放上代码:
select
c.difficult_level,
sum(if(b.result='right',1,0))/count(b.result) as correct_rate
from question_practice_detail b
left join user_profile a on a.device_id=b.device_id
left join question_detail c on b.question_id=c.question_id
where university='浙江大学'
group by c.difficult_level
order by correct_rate asc
思路拆解:
思路拆解:
(1)信息不完全,所以要关联三张表,需要的信息才都会cover住;
(2)筛选出浙大的信息,并且根据难度来分级,正确率排序;
(3)难点是怎么算correct_rate:要用到if函数,做对的题目数量/总题目数量 这里sum和count怎么用要搞清楚