Windowing ranking
Definition
The RANK() function is a window function that assigns a rank to each row within a partition of a result set. The rows within a partition that have the same values will receive the same rank. The rank of the first row within a partition is one.
Parameters
-
Partition by (+add):
- Def: Specify the column for grouping.
-
Order by (+add):
- Def: Specify the column for ordering.
-
Function:
- Def: Specify the function to use.
-
N:
- Def: Specify the size of rows.
-
Column output:
- Def: Specify the name of the column.
Additionnal Comments
Functions:
-
rank:
- Def: Returns a rank to each row in the partition of a result set. The rank of a row is determined by one plus the number of ranks that come before it.
-
dense_rank:
- Def: Returns a rank to each row in the partition of a result set. The rank values are not skipped in case of ties.
-
ntile:
- Def: Distributes rows of an ordered partition into a specified number of approximately equal groups. It assigns each group a bucket number starting from one to N.
-
percent_rank:
- Def: Returns the percentile ranking of rows in a result set : percent_rank = (rank - 1) / (total_rows - 1).
-
row_number:
- Def: Returns a sequential integer to each row of a query’s result set. Rows are ordered starting from one based on the order specified by the ORDER BY clause in the window definition.