题解 | #查询各个岗位分数的中位数位置的范围#

考试分数(四)

http://www.nowcoder.com/practice/502fb6e2b1ad4e56aa2e0dd90c6edf3c

想法1:考虑奇偶性

select m.job, 
       case when ct % 2 = 1 then ceiling(ct/2) else round(ct/2) end as start,
       case when ct % 2 = 1 then ceiling(ct/2) else round(ct/2+1) end as end
  from (
        select job, count(1) ct
          from grade
         group by job 
       ) m
 order by job;

想法2:不考虑奇偶性

select job,
       floor((count(job)+1)/2) as start,
       ceiling((count(job)+1)/2) as end
  from grade
 group by job
 order by job;
全部评论

相关推荐

10-25 00:32
香梨想要offer:感觉考研以后好好学 后面能乱杀,目前这简历有点难
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务