Quiz di SQL: Running Totals, LAG & LEAD

This SQL quiz covers aggregate window functions and the offset functions LAG() and LEAD(). You will compute running totals and moving averages, compare each row with the previous one and run into the default window frame that surprises many developers when the sort order has ties.

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 sales (day INTEGER, amount INTEGER);
INSERT INTO sales VALUES (1, 10), (2, 20), (3, 5), (4, 15);
SELECT day, SUM(amount) OVER (ORDER BY day)
FROM sales
ORDER BY day;
Mostra la risposta

A. 1|10 2|30 3|35 4|50 With ORDER BY inside OVER, the sum runs from the first row up to the current one, giving a running total. Unlike GROUP BY, every row is kept.

Cosa copre questo quiz

  • Running totals with SUM(...) OVER (ORDER BY ...)
  • LAG and LEAD with offsets and default values
  • Frames: ROWS BETWEEN ... AND CURRENT ROW
  • The default RANGE frame and ties
  • Per-group running totals with PARTITION BY

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.