sign up today

Ready to Go Pro with Maven Analytics

Ready to Go Pro with Maven Analytics

Sign up today an unlock full access to all data and AI learning content.

free email course

SQL with AI

Day 2

Intermediate

free email course

SQL with AI

Day 2

Intermediate

The Brief

Welcome back, it's John at Maven Analytics here again!

Yesterday you rewrote a subquery as a CTE and built a monthly revenue summary with a CTE chain. Today I want to talk about the structural mistake that makes CTEs harder than they need to be, and the clean alternative.

The mistake: doing too much in one CTE

The whole point of a CTE chain is that each step does one thing and does it clearly. When analysts pack multiple calculations into a single CTE, they get something that's marginally better than a subquery but still hard to read, impossible to test incrementally, and fragile when the business question changes.

The fix: one job per CTE. If a CTE is doing more than one calculation, split it.

Environment Setup

Environment Setup

exercise 1

Build a well-structured segment revenue CTE chain

5 min

exercise 1

Build a well-structured segment revenue CTE chain

5 min

exercise 2

Add a fourth CTE to flag outlier customers

5 min

exercise 2

Add a fourth CTE to flag outlier customers

5 min

exercise 3

Stress-test your own query

5 min

exercise 3

Stress-test your own query

5 min

Go Deeper

Go Deeper

Looking forward to Tomorrow

Looking forward to Tomorrow

© Maven Analytics, LLC | All Rights Reserved

© Maven Analytics, LLC | All Rights Reserved

© Maven Analytics, LLC | All Rights Reserved