当前位置:网站首页>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)
边栏推荐
- GoLand永久激活
- ICML2022 | 可扩展深度高斯马尔可夫随机场
- Modify large online games through CE modifier
- MySQL client tools are recommended. I can't imagine that it is best to use Juran
- Go from introduction to actual combat - context and task cancellation (notes)
- 空指针异常
- squid代理服务器
- gomock mockgen : unknown embedded interface
- 快递e栈——数组篇小型项目
- squid代理服務器
猜你喜欢

关于异常处理的知识整理

ICML2022 | 可扩展深度高斯马尔可夫随机场

squid代理服务器

Go from introduction to actual combat -- channel closing and broadcasting (notes)

微服务之远程调用

Null pointer exception

Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer

数据平台调度升级改造 | 从Azkaban 平滑过度到Apache DolphinScheduler 的操作实践

划重点!国产电脑上安装字体小技巧

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
随机推荐
Null pointer exception
mysql使用笔记一
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
Focus! Tips for installing fonts on domestic computers
Go从入门到实战——多态(笔记)
SQL必需掌握的100个重要知识点:IN 操作符
猜拳游戏专题训练
如何将队列里面的内容没秒钟执行一次优先级
覆盖接入2w+交通监测设备,EMQ 为深圳市打造交通全要素数字化新引擎
Covering access to 2w+ traffic monitoring equipment, EMQ creates a new digital engine for all elements of traffic in Shenzhen
数组作业题
AI painting minimalist tutorial
Codeforces Round #721 (Div. 2)
squid代理服务器
Oracle的CTAS能不能将约束等属性带到新表?
uniapp拦截请求
Knowledge sorting of exception handling
Go from entry to practice - dependency management (notes)
Industry case | see the operation of bank digital transformation from the king of retail
2021全球独角兽榜发布:中国301家独角兽企业全名单来了!