题解 | #SQL类别高难度试卷得分的截断平均值#

SQL类别高难度试卷得分的截断平均值

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

with a as(
select i.exam_id,max(r.score) as maxScore,min(r.score) as minScore 
from exam_record r,examination_info i 
where r.exam_id = i.exam_id and i.difficulty = 'hard' and r.score is not null
group by i.exam_id
)

select i.tag,i.difficulty,round(avg(r.score),1) from exam_record r,examination_info i 
where r.exam_id = i.exam_id and i.difficulty = 'hard' and r.score is not null
and not exists(select 1 from a where a.exam_id = i.exam_id and a.maxScore = r.score)
and not exists(select 1 from a where a.exam_id = i.exam_id and a.minScore = r.score)
group by i.tag,i.difficulty

先按科目ID分组取出最大最小的得分,然后再排除最大最小得分之后分组。

#SQL进阶#
全部评论

相关推荐

09-11 19:49
门头沟学院 Java
点赞 评论 收藏
分享
用微笑面对困难:只要你保证项目和获奖都是真的就行尤其是“对战,总负责人”啊这些套职,基本上队员,打杂的都这么写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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