with t_rank as ( select *, count(score) over(partition by job) as cnt, row_number() over(partition by job order by score,id) as a, row_number() over(partition by job order by score desc,id desc) as b from grade ) select id,job,score,b from t_rank where a >= cnt / 2 and b >= cnt / 2 order by id
中位数就是正序逆序排列都位于中间的数,两次排序后去找中间的位置