How do we rank items with tie handling (gaps vs contiguous ranks)?
RANK() leaves gaps after ties (1, 2, 2, 4), while DENSE_RANK() assigns consecutive numbers (1, 2, 2, 3).
Leaderboards, competition scoring, top salary tiers with accurate tie handling.
SELECT name,
salary,
RANK() OVER (
ORDER BY salary DESC
) AS rank,
DENSE_RANK() OVER (
ORDER BY salary DESC
) AS dense_rank
FROM employees;Practice typing production-grade SQL code for SQL RANK() & DENSE_RANK().