|
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, This week's newsletter is a bit different. There's SQL in here, but the real topic is career strategy. Because one of the most common questions I get from readers is some version of: "I've been learning SQL for a few months. How do I prove I can actually do this job?" The honest answer: a portfolio of 2-3 projects that demonstrate business thinking, not just technical syntax. The problem is most portfolios I've reviewed look the same. A Kaggle competition. A tutorial from...
Hello Reader, A common analytics question that sounds simple but isn't: "Which customers have booked the same type of expedition more than once?" You can't answer this with a regular JOIN between two different tables. The information lives in one table. You need to compare rows within that table to find patterns. That's what a self-JOIN does. It joins a table to itself. It sounds unusual, but once you see the pattern, you'll recognize situations where it's exactly what you need. The Business...
Hello Reader, You've built a clean customer report. Locations, booking history, revenue by region. You send it off to whoever asked for it. Ten minutes later: "Why does this report show blank cells in the location column? And why do the totals not add up?" Welcome to the NULL problem. You're going to learn how to solve it once and for all today. In the Summit Adventures database (the fake adventure tourism company I created to help people learn business analytics), 78.2% of customers don't...