题解 | #牛客的课程订单分析(三)#
最差是第几名(二)
http://www.nowcoder.com/practice/165d88474d434597bcd2af8bf72b24f1
select grade from class_grade a4 , ( select * from (select grade as g1 from (select sum(number)as sum,round(sum(number)/2) as s,if(sum(number)%2=0,round(sum(number)/2)+1,round(sum(number)/2))as e from class_grade)as pos, ( select grade, ( select sum(number) from class_grade c1 where c1.grade<=cg.grade ) as r, ( select count(grade) from class_grade c1 where c1.grade<=cg.grade ) as c from class_grade cg group by grade order by grade ) as g where g.r>=pos.s limit 1) as a1 join (select grade as g2 from (select sum(number)as sum,round(sum(number)/2) as s,if(sum(number)%2=0,round(sum(number)/2)+1,round(sum(number)/2))as e from class_grade)as pos, ( select grade, ( select sum(number) from class_grade c1 where c1.grade<=cg.grade ) as r, ( select count(grade) from class_grade c1 where c1.grade<=cg.grade ) as c from class_grade cg group by grade order by grade ) as g where g.r>=pos.e limit 1) as a2 )as a3 where a4.grade=a3.g1 or a4.grade=a3.g2 order by grade