当前位置:网站首页>GBase 8a OLAP分析函数cume_dist的使用样例
GBase 8a OLAP分析函数cume_dist的使用样例
2022-06-27 19:33:00 【生命之源;】
GBase 8a支持cume_dist 函数,用于计算小于等于或者大于等于(根据order的顺序)该值的百分比。
语法
cume_disk() over([partition by ] order by [desc])
说明
其中partition是否开窗,否则全部数值统一处理。
order by 的顺序,ASC(默认) = 小于等于,DESC =大于等于
样例
小于等于
如下例子是默认的升序,第一行表示:小于等于数值1的行数比例为20%
gbase> select id,cume_dist()over(order by id) cr from t2;
±-----±----+
| id | cr |
±-----±----+
| 1 | 0.2 |
| 2 | 0.4 |
| 3 | 0.6 |
| 4 | 0.8 |
| 5 | 1 |
±-----±----+
5 rows in set (Elapsed: 00:00:00.01)
大于等于
排序为desc,第一行表示:大于等于数值5的行数比例为20%。
gbase> select id,cume_dist()over(order by id desc) cr from t2;
±-----±----+
| id | cr |
±-----±----+
| 5 | 0.2 |
| 4 | 0.4 |
| 3 | 0.6 |
| 2 | 0.8 |
| 1 | 1 |
±-----±----+
5 rows in set (Elapsed: 00:00:00.02)
带开窗partition
每个partition内不分别计算百分比。
gbase> select * from t4;
±-----±-----+
| id | type |
±-----±-----+
| 1 | A |
| 2 | A |
| 3 | A |
| 1 | B |
| 2 | B |
| 3 | B |
| 4 | B |
±-----±-----+
7 rows in set (Elapsed: 00:00:00.00)
gbase> select type,id,cume_dist()over(partition by type order by id) cr from t4;
±-----±-----±------------------+
| type | id | cr |
±-----±-----±------------------+
| A | 1 | 0.333333333333333 |
| A | 2 | 0.666666666666667 |
| A | 3 | 1 |
| B | 1 | 0.25 |
| B | 2 | 0.5 |
| B | 3 | 0.75 |
| B | 4 | 1 |
±-----±-----±------------------+
7 rows in set (Elapsed: 00:00:00.07)
与Percent_rank的对比
percent_rank是计算相对位置,包含起点0,而cume_dist是包含等于的,所以不会出现0。如果数据只有1行,那么percent_rank为几点0, 而cume_dist为1(100%)。
gbase> select id,cume_dist()over(order by id) cr,percent_rank()over(order by id) pr from t2;
±-----±----±-----+
| id | cr | pr |
±-----±----±-----+
| 1 | 0.2 | 0 |
| 2 | 0.4 | 0.25 |
| 3 | 0.6 | 0.5 |
| 4 | 0.8 | 0.75 |
| 5 | 1 | 1 |
±-----±----±-----+
5 rows in set (Elapsed: 00:00:00.01)
一行数据
gbase> select id,cume_dist()over(order by id) cr,percent_rank()over(order by id) pr from t5;
±-----±—±—+
| id | cr | pr |
±-----±—±—+
| 1 | 1 | 0 |
±-----±—±—+
1 row in set (Elapsed: 00:00:00.02)
边栏推荐
- SQL必需掌握的100个重要知识点:用通配符进行过滤
- At 19:00 on Tuesday evening, the 8th live broadcast of battle code Pioneer - how to participate in openharmony's open source contribution in multiple directions
- 于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日
- 请教CMS小程序首页的幻灯片在哪里设置?
- SQL必需掌握的100个重要知识点:排序检索数据
- 互联网 35~40 岁的一线研发人员,对于此岗位的核心竞争力是什么?
- Codeforces Round #722 (Div. 2)
- MySQL usage notes 1
- 富文本 考试 填空题
- Here are 12 commonly used function formulas for you. All used ones are good
猜你喜欢
Go从入门到实战——Panic和recover(笔记)
Ceph分布式存储
Null pointer exception
Data platform scheduling upgrade and transformation | operation practice from Azkaban smooth transition to Apache dolphin scheduler
Go from entry to practice - multiple selection and timeout control (notes)
SQL必需掌握的100个重要知识点:排序检索数据
∫(0→1) ln(1+x) / (x ² + 1) dx
PCIE知识点-008:PCIE switch的结构
Codeforces Round #719 (Div. 3)
创建对象时JVM内存结构
随机推荐
100 important knowledge points that SQL must master: combining where clauses
本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
How to delete "know this picture" on win11 desktop
How to participate in openharmony code contribution
MySQL usage notes 1
Squid proxy server
互联网 35~40 岁的一线研发人员,对于此岗位的核心竞争力是什么?
安装gatewayworker之后启动start.php
"Apprendre cette image" apparaît sur le Bureau win11 comment supprimer
DO280OpenShift访问控制--security policy和章节实验
Ceph分布式存储
Go从入门到实战——行为的定义和实现(笔记)
Codeforces Global Round 14
oracle迁移mysql唯一索引大小写不区分别怕
Golang 使用正则来匹配出子字符串函数
请教CMS小程序首页的幻灯片在哪里设置?
GBase 8a V8版本节点替换期间通过并发数控制资源使用减少对系统影响的方法
win11桌面出現“了解此圖片”如何删除
GBase 8a OLAP分析函数cume_dist的使用样例
GBase 8a OLAP函数group by grouping sets的使用样例