Window Functions

Ranking, top-N per group, LAG and running totals

50 min · interactive lesson with runnable code and 6 graded exercises.

What you'll be able to do

  • Explain how a window differs from GROUP BY
  • Pick ROW_NUMBER, RANK or DENSE_RANK based on how ties should behave
  • Write top-N per group and latest-row-per-key with a CTE
  • Compute period-over-period change, running totals and moving averages

The full lesson is free with an account.

What a window does

ROW_NUMBER, RANK, DENSE_RANK

Top-N per group

LAG and LEAD

Running and moving totals

Filtering on a window