题解 | #浙大不同难度题目的正确率#

浙大不同难度题目的正确率

https://www.nowcoder.com/practice/d8a4f7b1ded04948b5435a45f03ead8c

select difficult_level, 
sum(if(result='right',1,0))/count(result) as correct_rate

from

user_profile as a, question_practice_detail as b, question_detail as c

where a.device_id = b.device_id and b.question_id = c.question_id
and a.university = '浙江大学'

group by difficult_level
order by correct_rate
 ;

1、表交建议统一用from+where即可

2、与上一题一贯套路,分组聚合时,原表假设有一列a,我们除了求agg(a),我们还可以求 agg(a的衍生),何为a的衍生,即a列的类似向量工程,条件函数、四则运算等,此题中 if(答题列 = 正确,若正确输出1,否则输出0)就是 “答题列的衍生”,最后我们求“答题列衍生”的agg,此处agg为sum

3、莫忘记最后还要排序。。。

全部评论

相关推荐

评论
点赞
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务