题解 | #考试分数(四)#
考试分数(四)
http://www.nowcoder.com/practice/502fb6e2b1ad4e56aa2e0dd90c6edf3c
先分组聚合函数求出各job的分数个数num, 再逻辑函数判断出num为奇或为偶,连接各自计算公式
select job,
case when mod(num,2)=1 then round((num+1)/2) else round(num/2) end as start,
case when mod(num,2)=0 then round(num/2+1) else round((num+1)/2) end as end
from (select job,count(id) num from grade group by job) t
order by job;