题解 | #考试分数(四)#
考试分数(四)
http://www.nowcoder.com/practice/502fb6e2b1ad4e56aa2e0dd90c6edf3c
select job,min(rk) start,max(rk) end
from(
select job,rk
from(
select *,count(*)over(partition by job) cnt,
rank()over(partition by job order by score) rk
from grade
) hh
where (cnt%2=0 and rk=cnt/2 or rk=cnt/2+1) or (cnt%2!=0 and rk=round(cnt/2) )
order by rk
) ww
group by job
order by job
from(
select job,rk
from(
select *,count(*)over(partition by job) cnt,
rank()over(partition by job order by score) rk
from grade
) hh
where (cnt%2=0 and rk=cnt/2 or rk=cnt/2+1) or (cnt%2!=0 and rk=round(cnt/2) )
order by rk
) ww
group by job
order by job