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.
7mIntermediate10,661 students

Sign in to watch this lesson
Browsing is free. Create an account to play videos and track your progress.
Overview
CTEs make a long query readable; window functions compute across related rows without collapsing them. Running totals and rankings stop being hard.
What this lesson covers
- Break a complex query into named CTEs
- Rank and number rows within partitions
- Compute running totals and row-to-row differences
This lesson sits in SQL Essentials, part of PostgreSQL for Developers. It assumes what came before it and leads directly into the next lesson in the module.
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.