Assign ordered rankings with or without gaps.

Section: Window Function Basics

Rank rows

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

RANK leaves gaps after ties; DENSE_RANK does not.

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 Window Function Basics
Assign row numbers
Number rows within an ordered partition.
OpenIn sheetsqlsame section
Compute running total
Accumulate values across an ordered window.
OpenIn sheetsqlsame section
Average within partition
Compute metrics per partition while keeping each row.
OpenIn sheetsqlsame section
Use LAG
Read a value from the previous row in the same partition.
OpenIn sheetsql1 tag match
Bucket rows with NTILE
Divide ordered rows into a fixed number of groups.
OpenIn sheetsql1 tag match
Use LEAD
Read a value from the next row in the same partition.
OpenIn sheetsql1 tag match