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

考试分数(五)

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

对分数排序 with a as (select *,row_number() over(partition by job order by score desc ) ranks from grade)

select a.* from a join (select job,case when ranks%2=1 then ceil(ranks/2) 判断数量是否为奇数,为基数可以直接取到中间值 when ranks%2=0 then round(ranks/2,0)为偶数则取中间的的一个数 end ranking from (select job,max(ranks) ranks,0 as rankss from a group by job) x union 将他们拼接 select job,case when ranks%2=1 then ceil(ranks/2) when ranks%2=0 then round(ranks/2+1,0)为偶数则取中间的第二个数 end ranking from (select job,max(ranks) ranks,0 as rankss from a group by job) x) b on a.job=b.job and a.ranks=b.ranking order by a.id

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-11 11:21
被夸真的超级开心,好可爱的姐姐
码农索隆:老色批们不用脑补了,我把金智妮的图找来了查看图片
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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