Lesson 1.3

CTEs and window functions

CTEs make a long query readable; window functions compute across related rows without collapsing them. Running totals and rankings stop being hard.

Duration
8m
Level
Intermediate
Students
11k students

Overview

CTEs make a long query readable; window functions compute across related rows without collapsing them. Running totals and rankings stop being hard.

In this lesson you will:

  • Break a complex query into named CTEs
  • Rank and number rows within partitions
  • Compute running totals and row-to-row differences

Resources

PostgreSQL documentation

The official reference for the tools used in this lesson.