当前位置: 首页 > news >正文

【牛客】SQL123 SQL类别高难度试卷得分的截断平均值

描述

牛客的运营同学想要查看大家在SQL类别中高难度试卷的得分情况。

请你帮她从exam_record数据表中计算所有用户完成SQL类别高难度试卷得分的截断平均值(去掉一个最大值和一个最小值后的平均值)。

示例数据:examination_info(exam_id试卷ID, tag试卷类别, difficulty试卷难度, duration考试时长, release_time发布时间)

idexam_idtagdifficultydurationrelease_time
19001SQLhard602020-01-01 10:00:00
29002算法medium802020-08-02 10:00:00

示例数据:exam_record(uid用户ID, exam_id试卷ID, start_time开始作答时间, submit_time交卷时间, score得分)

iduidexam_idstart_timesubmit_timescore
1100190012020-01-02 09:01:012020-01-02 09:21:0180
2100190012021-05-02 10:01:012021-05-02 10:30:0181
3100190012021-06-02 19:01:012021-06-02 19:31:0184
4100190022021-09-05 19:01:012021-09-05 19:40:0189
5100190012021-09-02 12:01:01(NULL)(NULL)
6100190022021-09-01 12:01:01(NULL)(NULL)
7100290022021-02-02 19:01:012021-02-02 19:30:0187
8100290012021-05-05 18:01:012021-05-05 18:59:0290
9100390012021-09-07 12:01:012021-09-07 10:31:0150
10100490012021-09-06 10:01:01(NULL)(NULL)

根据输入你的查询结果如下:

tagdifficultyclip_avg_score
SQLhard81.7


从examination_info表可知,试卷9001为高难度SQL试卷,该试卷被作答的得分有[80,81,84,90,50],去除最高分和最低分后为[80,81,84],平均分为81.6666667,保留一位小数后为81.7

输入描述:

输入数据中至少有3个有效分数

with cte as (
    select exam_id,score,tag,difficulty,
    dense_rank() over (partition by exam_id order by score) as rnk1,
    dense_rank() over (partition by exam_id order by score desc) as rnk2
    from 
    exam_record left join examination_info using (exam_id)
    where score is not null and tag = 'SQL'and difficulty = 'hard'
)

select tag,difficulty,
round(avg(score),1) as clip_avg_score
from cte
where score between 
(select score from cte where rnk1=2) 
and (select score from cte where rnk2=2)
group by tag,difficulty

或:

with cte as (
    select exam_id,score,tag,difficulty,
    dense_rank() over (partition by exam_id order by score) as rnk1,
    dense_rank() over (partition by exam_id order by score desc) as rnk2
    from 
    exam_record left join examination_info using (exam_id)
    where score is not null and tag = 'SQL'and difficulty = 'hard'
)

select tag,difficulty,
round(avg(score),1) as clip_avg_score
from cte
where rnk1!=1 and rnk2!=1
group by tag,difficulty

相关文章:

  • 支持国密ssl的curl编译和测试验证(下)
  • 什么是高可用架构
  • 代码随想录|学习工具分享
  • Spring Boot自动装配原理
  • 【LeetCode】【滑动窗口长度不固定】978 最长湍流子数组
  • 合并spark structured streaming处理流式数据产生的小文件
  • 多模态表征—CLIP及中文版Chinese-CLIP:理论讲解、代码微调与论文阅读
  • 使用React和ResizeObserver实现自适应ECharts图表
  • prometheus监控带安全认证的elasticsearch
  • docker创建mongodb数据库容器
  • Aigtek前置微小信号放大器在传感器检测中的应用有哪些
  • STM32—触摸键
  • @ 代码随想录算法训练营第4周(C语言)|Day22(二叉树)
  • 【MySQL】表的操作
  • React18源码: reconcliler启动过程
  • ✅鉴权—cookie、session、token、jwt、单点登录
  • C语言读取用户输入的常用函数
  • django学习网址
  • 【了解机器学习的定义与发展历程】
  • nifi连接Sql server数据库报错TLS问题
  • 原创话剧风向标!这个展演上《大宅门》《白鹿原》先后上演
  • 夜读丨庭院春韵
  • 传染病防治法修订草案提请三审,拟加强医疗机构疾控能力建设
  • 京东美团开打,苦了商家?
  • 广汽集团一季度净亏损7.3亿元,同比转亏,总销量下滑9%
  • 第三款在美获批的国产PD-1肿瘤药来了,影响多大?