当前位置:网站首页>Gbase 8A OLAP analysis function cume_ Example of dist
Gbase 8A OLAP analysis function cume_ Example of dist
2022-06-27 21:53:00 【The source of life;】
GBase 8a Support cume_dist function , Used to calculate less than or equal to or greater than ( according to order The order of ) Percentage of this value .
grammar
cume_disk() over([partition by ] order by [desc])
explain
among partition Whether to open a window , Otherwise, all values shall be treated uniformly .
order by The order of ,ASC( Default ) = Less than or equal to ,DESC = Greater than or equal to
Examples
Less than or equal to
The following example is the default ascending order , The first line means : Less than or equal to value 1 The proportion of rows of is 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)
Greater than or equal to
The order is desc, The first line means : A value greater than or equal to 5 The proportion of rows of is 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)
With window partition
Every partition The percentages are not calculated separately .
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)
And Percent_rank Comparison of
percent_rank Is to calculate the relative position , Including the starting point 0, and cume_dist It contains equal to , So it won't show up 0. If the data is only 1 That's ok , that percent_rank For what time 0, and cume_dist by 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)
A line of data
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)
边栏推荐
- io流代码
- CORBA 架构体系指南(通用对象请求代理体系架构)
- [LeetCode]508. 出現次數最多的子樹元素和
- 关于异常处理的知识整理
- [LeetCode]513. Find the value in the lower left corner of the tree
- Common methods of string class
- Go from entry to practice - multiple selection and timeout control (notes)
- 微服务之远程调用
- Icml2022 | scalable depth Gaussian Markov random field
- qt 大文件生成md5校验码
猜你喜欢
Codeforces Round #719 (Div. 3)
How to participate in openharmony code contribution
Process control task
【MySQL】数据库函数通关教程下篇(窗口函数专题)
Codeforces Round #716 (Div. 2)
本周二晚19:00战码先锋第8期直播丨如何多方位参与OpenHarmony开源贡献
I think I should start writing my own blog.
Slow bear market, bit Store provides stable stacking products to help you cross the bull and bear
Go from introduction to actual combat - package (notes)
Go從入門到實戰——接口(筆記)
随机推荐
[LeetCode]30. Concatenate substrings of all words
Interval DP of Changyou dynamic programming
GBase 8a OLAP函数group by grouping sets的使用样例
CORBA 架构体系指南(通用对象请求代理体系架构)
[LeetCode]186. Flip word II in string
[leetcode] dynamic programming solution partition array ii[arctic fox]
分享|智慧环保-生态文明信息化解决方案(附PDF)
vmware虚拟机PE启动
Little known MySQL import data
空指针异常
Oracle migration MySQL unique index case insensitive don't be afraid
Quick excel export according to customized excel Title Template
Go从入门到实战——共享内存并发机制(笔记)
Magic POI error in reading excel template file
Have time to look at ognl expressions
石子合并问题分析
C语言程序设计详细版 (学习笔记1) 看完不懂,我也没办法。
流程控制任务
excel读取文件内容方法
Method of reading file contents by Excel