当前位置:网站首页>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)
边栏推荐
猜你喜欢

Process control task

∫(0→1) ln(1+x) / (x² + 1) dx

Go从入门到实战——行为的定义和实现(笔记)

STM32F107+LAN8720A使用STM32cubeMX配置网络连接+tcp主从机+UDP app

跟我一起AQS SOS AQS

洛谷P5706 再分肥宅水

Go from introduction to actual combat - context and task cancellation (notes)

Stm32cubeide1.9.0\stm32cubemx 6.5 f429igt6 plus lan8720a, configure eth+lwip

Icml2022 | scalable depth Gaussian Markov random field

Go从入门到实战——任务的取消(笔记)
随机推荐
分享|智慧环保-生态文明信息化解决方案(附PDF)
畅游动态规划之区间DP
Codeforces Round #716 (Div. 2)
石子合并问题分析
[leetcode] 508. Élément de sous - arbre le plus fréquent et
Go从入门到实战——行为的定义和实现(笔记)
Go从入门到实战——接口(笔记)
. Net learning notes (V) -- lambda, LINQ, anonymous class (VaR), extension method
Quick excel export
[LeetCode]161. Edit distance of 1
QT base64 encryption and decryption
Go from introduction to practice - polymorphism (note)
图解基于AQS队列实现的CountDownLatch和CyclicBarrier
[LeetCode]508. 出现次数最多的子树元素和
∫(0→1) ln(1+x) / (x ² + 1) dx
Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
鲜为人知的mysql导入数据
Acwing周赛57-最长连续子序列-(二分or树状数组)
[LeetCode]动态规划解分割数组I[Red Fox]
Method of reading file contents by Excel