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

考试分数(五)

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

WITH grade_count AS (
    SELECT job, COUNT(job) AS job_cnt
    FROM grade
    GROUP BY job
),
grade_rank AS (
    SELECT id, job, score, DENSE_RANK() OVER (
    PARTITION BY job
    ORDER BY score DESC) AS d_rank
    FROM grade
    ORDER BY id ASC
)

SELECT r.id, r.job, r.score, r.d_rank
FROM grade_rank AS r
LEFT JOIN grade_count AS c
ON r.job = c.job
WHERE r.d_rank = (c.job_cnt + 1)/2
OR r.d_rank = c.job_cnt/2
OR r.d_rank = c.job_cnt/2 + 1
ORDER BY id ASC;

全部评论

相关推荐

牛客279957775号:铁暗恋
点赞 评论 收藏
分享
牛客410815733号:这是什么电影查看图片
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务