关于中位数的特征

考试分数(四)

http://www.nowcoder.com/questionTerminal/502fb6e2b1ad4e56aa2e0dd90c6edf3c

#中位数的特征:
#当个数为偶数时,中位数的起始位置等于个数/2,结束位置等于个数/2+1
#当个数为奇数时,中位数的起始位置等于向上取整(个数/2),结束位置等于向上取整(个数/2)
#用除以2的余数是否为0来判断奇偶,%2=0
#记得取整数,本题用ceiling函数向上取整(返回不小于该数的最小整数值)或round(数,0)四舍五入取整都可。
select job
        ,case when count(score)%2=0 then ceiling(count(score)/2) else ceiling(count(score)/2)
        end as start1
        ,case when count(score)%2=0 then ceiling(count(score)/2+1) else ceiling(count(score)/2)
        end as end1
from grade
group by job
order by job;


全部评论
是偶数的话,可不可不要用 ceiling,直接用 count(score)/2 作为 start ,(count(score)/2)+1 作为 end ?
点赞 回复 分享
发布于 2021-04-07 16:24
select job,round(count(*)/2,0) start,round((count(*)+1)/2,0) end from grade group by job order by job
1 回复 分享
发布于 2023-03-17 21:14 广东
这样也可以select job, case when count(score) % 2 =1 then count(score) div 2 + 1 when count(score) % 2 =0 then count(score) div 2 end as start, case when count(score) % 2 =1 then count(score) div 2 + 1 when count(score) % 2 =0 then count(score) div 2 + 1 end as end from grade group by job order by job
点赞 回复 分享
发布于 2023-01-20 22:12 山西
start部分不需要做判断,直接ceiling(count(score)/2) as start就可以了
点赞 回复 分享
发布于 2022-08-29 12:55 河南

相关推荐

评论
47
3
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务