PostgreSQL for Developers
LESSON 1.3

CTEs and window functions

Learn key techniques and workflows in PostgreSQL for Developers.

7m
intermediate
10,661 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

Pro Tip

When you catch yourself writing a subquery inside a subquery, a CTE will make it readable.

Resources