思路:case when函数 + 子查询

首先,获取各个岗位的总个数,按job分类汇总得到表t;

然后,使用case when函数分别获取各职位岗位分数中位数的起始位置和终止位置;

最后,将查询结果按job升序排列。

select t.job,
case when t.cs mod 2 = 1 then floor(t.cs/2)+1 else floor(t.cs/2) end as start,
case when t.cs mod 2 = 1 then floor(t.cs/2)+1 else floor(t.cs/2)+1 end as end 
from 
(select job,count(score) cs from grade group by job) t
order by t.job