题解 | #最差是第几名(二)#
最差是第几名(二)
https://www.nowcoder.com/practice/165d88474d434597bcd2af8bf72b24f1
写得不好,自己玩的,我其实想要explode的但是好像mysql这里用不了,有一种情况比如偶数的时候都落在了一个grade,应该显示两个还是一个,题好像没有考虑这个问题。这个方案只能说是我妥协后的思路吧,不太行感觉
select grade from ( select grade, case when allNums mod 2 = 0 then if((allNums / 2 > (end - number) and allNums / 2 <= end) or (allNums/2 + 1 > (end - number) and allNums / 2 + 1 <= end),1,0) else if(ceil(allNums/2) > (end - number) and ceil(allNums/2) <= end,1,0) end as flag from ( select grade,sum(number) over(order by grade) as end,number, sum(number) over() as allNums from class_grade ) t1 ) t2 where flag = 1 order by grade