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

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

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

select tag,difficulty,round(sum(score)/count(score),1) clip_avg_score from
(select
  uid,exam_id,score,tag,difficulty,
  first_value(score) over(order by score desc rows between unbounded preceding and unbounded following) max_value,
  last_value(score) over(order by score desc rows between unbounded preceding and unbounded following) min_value
from
(select uid,ei.exam_id exam_id,score,tag,difficulty from exam_record er
left join
examination_info ei
on er.exam_id = ei.exam_id
where
  ei.tag = 'SQL'
  and ei.difficulty = 'hard'
  and score is not null) a) t
where t.score <> max_value and t.score <> min_value
group by tag,difficulty
用到窗口函数,找到最大值和最小值
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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