RANIARANIA Academy

Window Functions

Learn to run analytics without collapsing rows using PostgreSQL window functions. You will master OVER, PARTITION BY and ORDER BY, ranking with ROW_NUMBER/RANK/DENSE_RANK, row-to-row comparisons with LAG and LEAD, and running totals and moving averages with explicit frames.

Watch the free preview

What window functions are — the OVER clause — free to watch, no account needed.

PostgreSQL INTERMEDIATE · 150 min · Certificate on completion · 3 CPD points

What you'll learn

  • Run analytics without collapsing rows using window functions and the OVER clause
  • Partition and order rows to compute per-group values while keeping every detail row
  • Rank rows within groups with ROW_NUMBER, RANK and DENSE_RANK
  • Compare each row to its neighbours with LAG and LEAD
  • Build running totals and moving averages with explicit ROWS and RANGE frames

Syllabus

Window Function Fundamentals — OVER and PARTITION BY
What window functions are — the OVER clauseFree preview15 min
PARTITION BY — per-group calculations that keep every row15 min
Ranking Within Groups
ROW_NUMBER, RANK and DENSE_RANK15 min
Ranking within groups and top-N per partition15 min
Navigation — LAG, LEAD and Positional Functions
LAG and LEAD — comparing to neighbouring rows15 min
Positional functions — FIRST_VALUE, LAST_VALUE, NTILE15 min
Running Totals, Moving Averages and Framing
Running totals and cumulative aggregates15 min
Framing — ROWS versus RANGE and moving averages15 min
Lab — 10 Exercises & Solutions
Exercises 1–515 min
Exercises 6–1015 min