SQL ROW_NUMBER, RANK & DENSE_RANK Quiz

This SQL quiz is about ranking window functions: ROW_NUMBER(), RANK() and DENSE_RANK(). You will predict how each handles ties, rank within groups with PARTITION BY and solve interview classics like top-N per group and the second highest value.

Hard 10 questions ~8 minutes Pass at 80% SQLite

Choose a mode

Playing as a guest: sign in to keep your XP and streak.

Sample question

Question 1 of 10

What does this print?

CREATE TABLE scores (name TEXT, score INTEGER);
INSERT INTO scores VALUES ('Ann', 90), ('Bob', 85), ('Cy', 90), ('Dee', 80);
SELECT name, RANK() OVER (ORDER BY score DESC)
FROM scores
ORDER BY name;
Show the answer

B. Ann|1 Bob|3 Cy|1 Dee|4 RANK() gives tied rows the same rank and then skips ahead: Ann and Cy share 1, so the next rank is 3, not 2. The final ORDER BY name only changes the display order.

What this quiz covers

  • How ROW_NUMBER, RANK and DENSE_RANK handle ties
  • PARTITION BY to rank within groups
  • Top-N per group with a ranked subquery
  • Why window functions can't go in WHERE
  • Tie-breakers for deterministic numbering

Questions people ask

Do I need an account?

No. Anyone can play. Sign in to keep your XP, streak, badges and history.

Can I retake it?

Yes. Your best score is kept, and the questions and answers are shuffled each time.