with count_temp as ( select job,count(*) as count from grade group by job ) select job,round(count/2) as start, case when count%2 != 0 then round(count/2) else round(count/2)+1 end as end from count_temp order by job;