Skip to main content
SQL โ€ข LESSON 143

RANK

How can we rank employees with gaps when salaries tie?

Advancedโฑ 3 Minutesโญ 1560 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