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

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

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

select (

    select tag

    from examination_info

    where tag='sql'

    limit 1

)

,(select difficulty

    from examination_info

    where tag='sql'

    limit 1)

,round((sum(score)-max(score)-min(score))/(count(uid)-2),1) clip_avg_score

from exam_record

where exam_id=(select exam_id

from examination_info

where tag='sql' and difficulty='hard'and score is not null

这道题我第一个想法就是用子查询来做,但是一般来说子查询运行速度很慢,所以想着用表连接再做一遍,写了一遍,发现自己写的代码还是很复杂:

select tag

,difficulty

,clip_avg_score

from examination_info

left join (

select round((sum(score)-max(score)-min(score))/(count(exam_id)-2),1) clip_avg_score

,exam_id

from exam_record

where score is not null

group by exam_id) ex

using(exam_id)

where tag='sql' and difficulty='hard'

想和各位交流一下,该怎么简化自己的代码呢?现在看到题目虽然能做出来,但是感觉思维一直都不是很简洁,感谢各位

全部评论

相关推荐

2025-11-07 15:41
暨南大学 C++
用微笑面对困难:我面试时候,就说了句”不愧是徐波的兵“他就破房了说是
点赞 评论 收藏
分享
2025-12-22 16:31
已编辑
桂林电子科技大学 Python
很奥的前端仔:如果你接了offer 临时又说不去 hr确实要多做一些工作。 当然如果是接offer之前当我没说
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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