Skip to main content
SQL • LESSON 143

RANK

How can we rank employees with gaps when salaries tie?

Advanced3 Minutes1560 XP
🤔 THE QUESTION

How can we rank employees with gaps when salaries tie?

💡 WHAT IS IT?

RANK() assigns identical ranks to tied values and skips subsequent numbers (e.g. 1, 2, 2, 4).

🎯 WHAT IS IT USED FOR?

Olympic/competition style rankings, academic standing, compensation benchmarks.

💻 EXAMPLE
SELECT
name,
salary,
RANK() OVER (ORDER BY salary DESC) AS salary_rank
FROM employees;

🎯 Mission Objectives

Practice typing production-grade SQL code for RANK.

  • RANK() function
  • Tie handling with gaps
  • Competition ranking
  • Window ordering