Section: Ranking functions

RANK

sql
sql
SELECT employee_id,
       department_id,
       salary,
       RANK() OVER (
         PARTITION BY department_id
         ORDER BY salary DESC
       ) AS salary_rank
FROM employees;
Explanation

When two rows tie for rank 1, the next rank becomes 3.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Ranking functions
ROW_NUMBER
Unique sequence with no ties.
OpenIn sheetsqlsame section
DENSE_RANK
Tied rows share rank without gaps.
OpenIn sheetsqlsame section
Split rows into quartiles with NTILE
Bucket ordered rows into four groups.
OpenIn sheetsqlsame section
Calculate percent rank
Relative position from 0 to 1.
OpenIn sheetsqlsame section
Cumulative distribution
Fraction of rows at or below the current row.
OpenIn sheetsqlsame section
Return top values including ties
Use RANK when tied rows should all qualify.
OpenIn sheetsql1 tag match