New: Cookbooks and AI ExplanationsStep-by-Step recipes to solve problems connected to Roadmaps and Cheat Sheets. Need more details? Use AI buttons for structured and simple explanations with concrete examples throughout the whole platform.Take a look
You open a report you inherited and it takes ten minutes just to work out what it returns.
What you'll have at the end
The same report rewritten as two or three named CTE steps that read from top to bottom
You need
A single report query that already runs and returns correct numbers, built from two or more subqueries nested inside each other.
Not covered
Making the rewritten query run faster is a separate problem from making it readable; this does not touch indexes or execution plans.
Combine three monthly sales exports into one table with UNION
go there first if the data behind this report is still split across separate monthly exports instead of one queryable table.
Track month over month growth with LAG
once the report reads cleanly from named CTEs, this shows how to add a month-over-month comparison as one more CTE in the same chain.
Checked 26 Aug 2026
Part of the SQL for Data Analysis cookbook