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

考试分数(五)

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

sql分解步骤,在之前的步骤之上进行排序即可

SELECT k.id,k.job,k.score,k.number AS t_rank
FROM
(
SELECT 
id,job,score,
RANK() OVER(PARTITION BY job ORDER BY score DESC,job) AS number
FROM grade
)k,
(
SELECT a.job, 
CASE (MIN(a.number) + MAX(a.number))%2
    WHEN 0 THEN
        ROUND((MIN(a.number) + MAX(a.number))/2,0)
    ELSE
        FLOOR((MIN(a.number) + MAX(a.number))/2)
END start,
CASE (MIN(a.number) + MAX(a.number))%2
    WHEN 0 THEN
        ROUND((MIN(a.number) + MAX(a.number))/2,0)
    ELSE
        CEIL((MIN(a.number) + MAX(a.number))/2)
END end
FROM
(
SELECT 
id,job,score,
RANK() OVER(PARTITION BY job ORDER BY score DESC,job) AS number
FROM grade
)a
GROUP BY
a.job
)l
WHERE
k.job = l.job
AND
(
k.number = l.start
OR
k.number = l.end
)
ORDER BY
id
全部评论

相关推荐

SinyWu:七院电话面的时候问我有没有女朋友,一听异地说你赶紧分。我:???
点赞 评论 收藏
分享
10-30 10:16
南京大学 Java
龚至诚:给南大✌️跪了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务