A handful of query patterns cover the majority of real analyst work. Master these shapes and most business questions become variations on a theme.
Key Points
- Top-N per category: ROW_NUMBER() OVER (PARTITION BY category ORDER BY sales DESC)
- Month-over-month growth: LAG(revenue) OVER (ORDER BY month)
- Deduplication: keep row 1 per group with ROW_NUMBER
- Running totals: SUM(amount) OVER (ORDER BY date)
- Cohort bases: first purchase date per customer via MIN + GROUP BY
- Funnel counts: conditional aggregation with CASE inside COUNT/SUM
.png)