Quiz di SQL: ROW_NUMBER, RANK & DENSE_RANK

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.

Difficile 10 domande ~8 minuti Superato con il 80% SQLite

Scegli una modalità

Stai giocando come ospite: accedi per salvare XP e serie.

Domanda di esempio

Domanda 1 di 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;
Mostra la risposta

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.

Cosa copre questo quiz

  • 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

Domande frequenti

Serve un account?

No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.

Posso rifarlo?

Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.