题解 | #考试分数(五)#

考试分数(五)

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

我就来一个通俗易懂,不需要妙解

仅需要知道case...when...then...end就好了。我是没想到它可以在where上使用,TQL

另外临时表真的是一个好东西啊,让代码清晰化

with t as (
    select
        id,
        job,
        score,
        row_number() over(partition by job order by score desc) as t_rank,
        count(job) over(partition by job) as job_num
    from grade
)


select
    id,
    job,
    score,
    t_rank
from t
where
    case
        when job_num % 2 = 0 then t_rank = job_num / 2 or t_rank = job_num / 2 + 1
        else t_rank = ceil(job_num / 2)
    end
order by id

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-30 18:19
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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