Overview
TheRANK() window function determines the rank of a value in a group of values, based on the ORDER BY expression
in the OVER clause. It can be used with all data types supported by Oxla.
Syntax
The syntax for this function is as follows:BIGINT and it indicates the rank of values in a table, regardles of the input types.
- If the optional
PARTITION BYexpression is present, the rankings are reset for each group of rows - If the
ORDER BYexpression is omitted then all ranks are equal to 1
Parameters
(): this function takes no arguments but parentheses is required
Examples
For the needs of this section, we will create thewinsales table that stores details about some sales transactions:
RANK() with ORDER BY
In this example, we will focus on executing theRANK() function with ORDER BY keyword and calculate the rank of all rows based on the quantity sold:
RANK() with ORDER BY and PARTITION BY
In this example, we will focus on executing theRANK() function with ORDER BY keyword and PARTITION BY clause, partition the table by seller ID, order each partition by the quantity and assign a rank to each row: