题解 | #考试分数(四)#
考试分数(四)
http://www.nowcoder.com/practice/502fb6e2b1ad4e56aa2e0dd90c6edf3c
SELECT job,
ROUND((CASE WHEN COUNT(r) % 2=1
THEN (COUNT(r)/2)+0.5 ELSE (COUNT(r)/2 END),0) AS start,
ROUND((CASE WHEN COUNT(r) % 2=1
THEN (COUNT(r)/2)+0.5 ELSE (COUNT(r)/2)+1 end),0) AS end
FROM
(SELECT job, RANK() OVER(PARTITION BY job ORDER BY score) r FROM grade
GROUP BY job, score) re
GROUP BY job
ORDER BY job