我是觉得逻辑很清晰的,直接case when每种情况
select job,
case when count(*) <= 2 then 1
when count(*) > 2 and count(*) % 2 = 1 then ceiling(count(*)/2)
else floor(count(*)/2)
end as start,
case when count(*) <= 2 then count(*)
when count(*) > 2 and count(*) % 2 = 1 then ceiling(count(*)/2)
else cast((count(*)/2 + 1) as unsigned)
end as 'end'
from grade
group by job
order by job

京公网安备 11010502036488号