题解 | #查询各个岗位分数的中位数位置的范围#
考试分数(四)
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;