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

考试分数(四)

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

//select count(*) as total ,job from grade GROUP BY job 先按照job分组计算有多少个
//当total=5 , 中位数start =(5+1)/2=3,total=6,start=6/2=3;
//当total=5 , 中位数end =(5+1)/2=3,total=6,start=6/2+1=4;
//奇数情况下中位数只有一个total=5, end和start都=3

select job,
round((case when total%2=0 then total/2 else (total +1) /2 end),0) as `start`  ,
round((case when total%2=0 then total/2+1 else (total+1)/2 end),0) as `end` 
from (select count(*) as total ,job from grade GROUP BY job )  a order by job;

全部评论

相关推荐

ldf李鑫:不说公司名祝你以后天天遇到这样的公司
点赞 评论 收藏
分享
ming_ri:“很抱歉,您的简历和我们当前的职位需求不是很匹配”
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务