题解 | #牛客每个人最近的登录日期(五)#

最差是第几名(二)

http://www.nowcoder.com/practice/165d88474d434597bcd2af8bf72b24f1

笨办法,将中位数和每个grade对应的排名区间列出来,中位数在排名区间内选中即可

with total as
(select sum(number) tnum from class_grade)
select grade from
(
select *
,sum(number) over(order by grade) - number + 1 as floor
,sum(number) over(order by grade) as celling
,floor(((select tnum from total)+1)/2) as lowm
,floor(((select tnum from total)+2)/2) as upperm
from class_grade c
)a
where (lowm>=floor and lowm<=celling) or (upperm>=floor and celling>=upperm)
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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