|
Hey Reader, Imagine you're presenting a finding to your team: "Customer A spent $4,200 with us." The first question from the room: "Is that a lot?" Most analysts learning SQL don't realize that, without context, the number means nothing. You need comparison. Is the average customer spend $500 or $5,000? Is $4,200 in the top 10% or the middle of the pack? This is the "compared to what?" problem, and subqueries solve it elegantly. Numbers without context don't drive decisions.Executives don't want to hear "$4,200." They want to hear "two times the average customer spend" or "top 5% of all customers." The challenge: the comparison values (averages, totals, benchmarks) live in the same tables as the individual records. You need a way to calculate both simultaneously. That's exactly what subqueries do. Customers vs. AverageHere's what I ran against the Summit Adventures database (the fake adventure tourism company I created to help people learn business analytics):
This shows each above-average customer, their total spending, the overall average, and how many times above average they are. Instead of saying "These customers spent a lot," you can now say "These 10 customers spend 3.5-6x the average. They represent our highest-value segment and deserve dedicated attention." Same data. Completely different impact. A Cleaner Approach: CTEsThat query above has repeated subqueries, which makes it harder to read. Here's the same logic using a CTE:
Same result, much more readable. The CTE calculates the average once and makes it available to the final query. Three "Compared to What?" PatternsPattern 1: Individual vs. Overall Average (shown above) "How does this customer compare to the average customer?" Pattern 2: Category vs. Category "How does hiking revenue compare to climbing revenue?"
Pattern 3: This Period vs. Last Period "How does this month compare to last month?"
Why "Compared to What?" Is the Most Important QuestionEarly in my career, I learned that raw numbers almost never drive decisions. It's the comparison that creates urgency:
Every time you present a metric, ask yourself: "Compared to what?" Then add that context to your query. Try This At Your JobPick any metric you report regularly — revenue, customer count, transaction volume — and add one comparison:
One comparison transforms a number into an insight. Until next time, Brian P.S. Adding context to your analysis is the core concept behind the So What Framework in Module 6 of SQL for Business Impact. Every number needs a "so what" — and subqueries are one way to build that context directly into your queries. Check it out at sqlforbusinessimpact.com. P.P.S. What's one metric you report that always gets the response "is that good or bad?" Hit reply and tell me — I can probably help you add the right comparison. I read every response. |
Learn to build analytics projects with SQL, Tableau, Excel, and Python. For data analysts looking to level up their career and complete beginners looking to get started. No fluff. No theory. Just step-by-step tutorials anyone can follow.
Hello Reader, Almost every business question boils down to one of two things: "How many?" (COUNT) "How much?" (SUM) How many customers booked this month? How much revenue did we generate? How many trips were cancelled? How much did we lose? Once you're comfortable with COUNT and SUM, you can answer the majority of questions that come your way (like sales analytics using SQL). Let me show you both patterns using a real business scenario. The Scenario Your operations manager asks: "Give me a...
HeyReader, Most analysts never think to ask: "Why are our customers cancelling?" Everyone looks at bookings. Everyone reports revenue. But the data hiding in your cancelled orders often tells a more important story than your completed ones. And analysts that want to move from beginner to intermediate SQL skill level have an unfair advantage here. Because there's a sequence to work through this kind of problem. That's what we're covering here. At Summit Adventures (the fake adventure tourism...
Hey Reader, Imagine you're a marketing analyst and your marketing director walks over and says: "I need our customers broken into spending tiers (VIP, Standard, and Low Value) so I can send different emails to each group." You have the data. But every customer just has a dollar amount. There's no "tier" column in the database. How do you create categories that don't exist yet? This is where CASE WHEN becomes one of the most useful tools in your SQL toolkit. The problem is that raw data...