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

考试分数(五)

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
全部评论

相关推荐

10-30 23:23
已编辑
中山大学 Web前端
去B座二楼砸水泥地:这无论是个人素质还是专业素质都👇拉满了吧
点赞 评论 收藏
分享
offer多多的六边形战士很无语:看了你的博客,感觉挺不错的,可以把你的访问量和粉丝数在简历里提一下,闪光点(仅个人意见)
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务