mysql--求中位数
2024-10-16 08:48:19
第一种求中位数方法:
/*
第一步:添加一个正序和反序
第二步:当列表数目为奇数的时候,列表选出的情况,当列表为偶数的时候列表的情况
第三步:统筹奇数和偶数时中位数
*/
select sum(Math)/count(*) as midean
from
(
select Math, desc_Math, asc_Math
from
(
select *, row_number() over (order by Math desc) as desc_Math,
row_number() over (order by Math asc) as asc_Math
from s448
)as order_table
where asc_Math in (desc_Math, desc_Math+1, desc_Math-1)) as media_number ;
第二种求中位数方法:
/*
第一步:为数据添加索引
第二步:利用索引找出数据的中位数
*/
set @rowidx := -1; -- 声明变量
select avg(n.Math) from
(select @rowidx := @rowidx + 1 as rowidx, Math from s448 order by Math) as n
where n.rowidx in (floor(@rowidx/2), ceil(@rowidx/2));
最新文章
- [POJ3667]Hotel(线段树,区间合并)
- USB Type-C接口完美无瑕?小心这五点
- 1207: C.LU的困惑
- DP HDIJ1421 搬宿舍
- Android 2.3 版本中链接边框问题解决
- QTREE - Query on a tree
- 从RGB色转为灰度色算法
- 在windows上搭建镜像yum站的方法(附bat脚本)
- docker~docker-compose的使用
- jsp 部署
- app模块设计
- 【BZOJ2208】【JSOI2010】连通数 传递闭包
- APP reset.css
- 如何创建.gitignore文件,忽略不必要提交的文件
- Vue.js学习笔记之修饰符详解
- AlertWindowManager 弹出提示窗口使用帮助(上)
- Hive 常用优化参数
- Python笔记 #04# Methods
- NJCTF 2017 web pictures'wall(详解)
- Educational Codeforces Round 10 C. Foe Pairs 水题
热门文章
- Android系统编程入门系列之硬件交互——传感器
- difflib模块详解
- [cf1515G]Phoenix and Odometers
- 六、Java API操作zookeeper节点
- 7.4 k8s结合ceph rbd、cephfs实现数据的持久化和共享
- 洛谷 P5400 - [CTS2019]随机立方体(组合数学+二项式反演)
- Codeforces 611H - New Year and Forgotten Tree(二分图多重匹配)
- 解决Package is not available (for R version XXX)?
- 【机器学习与R语言】13- 如何提高模型的性能?
- Augustus指南(Trainning部分)