Day 4 of 45 · SQL Masterclass · Free

Day 4: Window Functions

Calculate running cumulative GMV, repeat customer purchase gaps, and top-3 products per category.

About 60 minutes of learning and 90 minutes of practice. It runs in your browser, with no install.

What you will be able to do

  • Calculate rankings, running totals, and moving averages without collapsing row cardinality.
  • Choose the correct ranking function between ROW_NUMBER, RANK, and DENSE_RANK for ties.
  • Compute time-series deltas and session gaps using LAG and LEAD over partitioned windows.

What the day covers

ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD, SUM OVER, AVG OVER, PARTITION BY, ORDER BY.

Questions you should be able to answer afterwards

  • How do ROW_NUMBER, RANK, and DENSE_RANK behave when 2 rows tie for second place?
  • What is the key difference between GROUP BY and an OVER (PARTITION BY ...) window function?
  • How do you calculate day-over-day revenue change using window functions?

Practice this day's skills

Each page shows the idea moving, then lists problems from easiest.

Builds on Day 3.

Days 1 to 7 are free. Days 8 to 45 need a pass; the plan page lists what each day covers, and the glossary defines each term.