SQL Running Totals, LAG & LEAD Quiz

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.

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 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;
Show the answer

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.

What this quiz covers

  • 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

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.