题解 | #考试分数(四)#

考试分数(四)

https://www.nowcoder.com/practice/502fb6e2b1ad4e56aa2e0dd90c6edf3c

with t as (select job,count(score) as num from grade 
group by job)
select job
     , ceil(num/2) as start
     , if(num%2=0,ceil(num/2)+1,ceil(num/2)) as end
   from t 
order by job

方法很多:if(条件表达式,满足条件的结果,不满足条件的返回值)简单

ceil()向上取整,floor()向下取整

注意:start时:无论是奇数还是偶数都一样ceil(num/2):ceil(num/2) as start

end时分情况,偶数是ceil(num/2)+1,奇数时ceil(num/2):if(num%2=0,ceil(num/2)+1,ceil(num/2)) as end

全部评论

相关推荐

威猛的小饼干正在背八股:挂到根本不想整理
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务