The Brief
Welcome to Day 4! It's still John at Maven Analytics here.
You've connected three tables, found a data quality issue, run a margin analysis, and identified your top customers. Today I'm adding the final tool in this week's toolkit: subqueries.
A subquery is a query inside a query. It lets you answer two-step questions, like "which customers spent more than average?", where you need to calculate the average first, then use it as a filter. You can't do that in a single GROUP BY.
The scenario
Sarah's final brief: "I want to focus retention efforts on high-value customers. Who's above average in spend, and what segments are they in? And are there any products that are significantly over-performing their category average? I want to prioritise those for next quarter's marketing."
Both questions are two-step. Both require subqueries.