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

考试分数(五)

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


# 先找排名,在根据排名挑选中位数

select
a.id
,a.job
,a.score
,a.ranking
from(
select
a.id
,a.job
,a.score
,a.total
,a.ranking
,round(if(a.total%2=0,total/2,(total+1)/2),0) as qian
,round(if(a.total%2=0,total/2+1,(total+1)/2),0) as hou
from(
select
a.id
,a.job
,a.score
,b.total as total
,row_number() over(partition by a.job order by a.score desc) as ranking
from grade a
join
(
select a.job,count(*) as total from grade a group by a.job
) b
on a.job=b.job
) a
) a
where a.ranking in(qian,hou)
order by a.id
;

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务