$ ./guess_the_languageSQL & Databases
SQL & Databases · medium · #44

What is r for the score 80?

-- scores: 90, 90, 80
SELECT score,
  RANK() OVER (ORDER BY score DESC) AS r
FROM t;
  1. 1
  2. 4
  3. 3
  4. 2
RANK leaves gaps after ties: both 90s are rank 1, so 80 is rank 3 (DENSE_RANK would give 2).
Play SQL & Databases ▸