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