select t3.id, t3.job, t3.score, t3.rn from (select *, row_number() over(partition by job order by score desc) as rn from grade) t3 join (select job, round(case when num%2 = 1 then (num+1) / 2 when num%2 = 0 then num/2 end,0) as 'start', round(case when num%2 = 1 then (num+1) / 2 when num%2 = 0 then (num/2)+1 end,0) as 'end' from (select job, count(*) as num from grade group by job) t1) t2 on t3.job = t2.job where t3.rn >= t2.start and t3.rn <= t2.end order by t3.id;

京公网安备 11010502036488号