RANK() (SQL)
A window function that assigns a rank to each row within the same window frame, starting with one.
Synopsis
RANK()
Description
RANK assigns a rank (an integer) to each row, starting with one. These ranks are determined by the values specified in the ORDER BY expression; for example, any rows that have the same value are given the same rank. However, unlike DENSE_RANK(), RANK() skips sequential numbers if two or more rows share the same rank — if two rows both have a rank of one, the next rank that will be assigned is three.
The ranks can include duplicate values if multiple rows contain the same value for the window function field.
Examples
The following example assigns a rank to each employee based on their salary within each department:
SELECT RANK() OVER (PARTITION BY Department ORDER BY Salary) FROM Company.Employee