Oracle内等距查询
来源:互联网 发布:域名泛解析 编辑:程序博客网 时间:2024/06/10 14:25
数据表内有列分数字段,分数0~600不等,现在需要统计各个分段内的人数,分段距离为50分计算一次,计算结果类似:
- 0~50 100
- 50~100 100
- 100~150 100
- 150~200 100
- ****
方案一:
一般写法为根据各个分数值进行case when判断是否在该区间内,然后赋值,代码如下:
select xyf,count(1) from (select (case when t.xyf >= 0 and t.xyf < 50 then '0~50' when t.xyf >= 50 and t.xyf < 100 then '50~100' when t.xyf >= 100 and t.xyf < 150 then '100~150' when t.xyf >= 150 and t.xyf < 200 then '150~200' when t.xyf >= 200 and t.xyf < 250 then '200~250' when t.xyf >= 250 and t.xyf < 300 then '250~300' when t.xyf >= 300 and t.xyf < 350 then '300~350' when t.xyf >= 350 and t.xyf < 400 then '350~400' when t.xyf >= 400 and t.xyf < 450 then '400~450' when t.xyf >= 450 and t.xyf < 500 then '450~500' when t.xyf >= 500 and t.xyf < 550 then '500~550' when t.xyf >= 550 and t.xyf < 600 then '550~600' else '其他' end) xyf from t_grxy_xyf t) group by xyf order by xyf;
得出结果如下:
优点:根据需求可以方便的调整统计结果,且简单易写。
缺点:繁琐的复制粘贴。。。
方案二:
根据分值,对当前分段进行取模,如:分数为120分,取模结果为:120/50=2,所属分段为:2*50~2*50+50,即100~150之间,实现代码如下:
select to_char(a * 50) || '~' || to_char(a * 50 + 50) 分段, count(1) 人数 from (select xyf, trunc(xyf / 50, 0) a from T_GRXY_XYF) group by a order by a;
得出结果如下:
1 0
- Oracle内等距查询
- Oracle 查询:一小时内、一天内、一周内等
- Oracle 查询:一小时内、一天内、一周内等
- oracle 内连接 外连接 查询 笔记
- oracle+hibernate 时间段内查询的方法:
- Oracle 查询一个月内的活动
- 等距采样
- oracle连接查询 内连接 外连接 全连接
- oracle sql中查询ip段内的记录
- Oracle 查询两个时间段内的所有日期列表
- Oracle查询某段日期内某个时间段的数据
- oracle 查询某一时间段内每个月的最后一天
- Oracle数据库 查询时间在当天内的数据sql
- Oracle查询某段日期内某个时间段的数据
- oracle内快速查询指定的表内的字段数
- Oracle SQL基础之(二) [联合查询、union、子查询、外、内连接、复制表]
- oracle----笛卡尔集---多表查询---内链--外链---子查询
- 等距节点插值
- 12.01常识(门户网站)
- CallableStatement执行存储过程
- Gson+retrofit解析同一位置不同类型的json数据
- 如何在cmd下切换不同版本的Python 原文:windows 安装python2 与python3 共存 地址:http://blog.csdn.net/liulucaro/article/de
- jquery控件
- Oracle内等距查询
- Linux中部署JAVA程序
- VS 和VC 的区别
- js方法中获取开始标签和结束标签中间插入内容的方式(innerHTML/html())
- Hbase葱岭探秘-原理与架构
- 矩阵的加法
- 自动打码软件怎么下载详解
- SQL SERVER 中如何用脚本管理作业
- 网络编程学习笔记一:Socket编程