Skip to content

Commit 1efa950

Browse files
committed
Rank() and Percent_Rank()
1 parent 1c57927 commit 1efa950

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--------------------- RANK () ---------------------------
2+
3+
-- we use Rank() when we want to know the relative oder of particular rows relative to other rows. (such as 1, 2, 3, etc.)
4+
-- the ranking 1, 2, 3 will restart when it reaches to another unique group.
5+
-- works same as Row_Number Function
6+
7+
8+
SELECT dept_id, server_id, cpu_utilization,
9+
RANK() OVER (PARTITION BY dept_id ORDER BY cpu_utilization DESC)
10+
FROM time_series.vw_utilization
11+
WHERE event_time BETWEEN '2019-03-05' AND '2019-03-06';
12+
13+
14+
--------------------- PERCENT_RANK () ---------------------------
15+
-- it is the rank divided by total numbers of rows (example: 0.0002, etc)
16+
17+
SELECT dept_id, server_id, cpu_utilization,
18+
PERCENT_RANK() OVER (PARTITION BY dept_id ORDER BY cpu_utilization DESC)
19+
FROM time_series.vw_utilization
20+
WHERE event_time BETWEEN '2019-03-05' AND '2019-03-06';
21+
22+
23+

0 commit comments

Comments
 (0)