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.