题解 | #考试分数(五)#
考试分数(五)
http://www.nowcoder.com/practice/b626ff9e2ad04789954c2132c74c0512
select id,job,score,rk t_rank
from(
select *,count(*)over(partition by job) cnt,
rank()over(partition by job order by score desc) 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 id