|
Hello Reader, Imagine you're a business analyst at Summit Adventures (the fake adventure tourism company I created to teach real-world business analytics concepts). Your CEO asks a common question: "Who are our best customers?" If you pull a list sorted by total spend, you'll get a spreadsheet with hundreds of rows. Not useful because no one acts on a list of 500 customers. And certainly not the CEO. What they actually need are segments: 3-5 groups with clear labels, clear revenue impact, and clear recommended actions for each. "Our 19 VIP customers generate 10.3% of total revenue" is something a team can work with. This is where CASE WHEN and GROUP BY combine.
How to help your team (in the real world)Gabby from marketing has budget for one targeted campaign next quarter. She needs to know: which customer group offers the best return? She can't market to everyone, so she needs clear segments with numbers. Step 1: Define Your Segments With CASE WHENThe first decision is the hardest: what thresholds define each segment? There's no universal rule, but here's a practical approach. Start with the data:
This tells you the range and distribution. Next, you choose breakpoints that create more meaningful groups that will drive actual action. If the max spend is $19k, let's mark any customers above $10k as VIP and then work down from there. (You can spend a LOT of time building and optimizing segments properly by a bunch of different criteria) Step 2: Build and Summarize Segments
Now we're talking! Let's read the story these numbers tell:
How CASE WHEN + GROUP BY Work TogetherThe key insight is understanding the division of labor: CASE WHEN creates the labels. It looks at each row and assigns it to a category:
GROUP BY collapses those categories into summary rows. It takes 1,000 individual customer records and produces 5 segment totals. The aggregation functions (COUNT, AVG, SUM) calculate metrics within each group. Without CASE WHEN, you'd have to create temporary tables or manual filters for each segment. Without GROUP BY, you'd have labeled rows but no summaries. Together, they turn raw data into a strategy document. Building Better Segments: Three VariationsVariation 1: Multi-dimensional segmentation Instead of just spending, combine value with recency:
Now "High Value - At Risk" is a retention emergency. Worth more investigation, for sure. Variation 2: Expedition engagement segments
This answers: "How deeply engaged are our customers?" Variation 3: Ticket size segments
This tells marketing which pricing tier each customer gravitates toward. Answering Gabby's QuestionBack to the original ask: where should Gabby focus her campaign budget?
The data says Option B (upgrading Light to Regular) has the highest potential return. These are customers who already trust you enough to buy. Getting a second or third booking from them is easier than acquiring new customers or preventing churn. Common Mistakes to AvoidMistake 1: Too many segments If you have 10 segments, you've created a spreadsheet, not a strategy. Aim for 3-5 groups with clear action items for each. Mistake 2: Using the same CASE WHEN in SELECT but not GROUP BY If your CASE WHEN appears in SELECT, the same expression must appear in GROUP BY. Otherwise you'll get an error or unexpected results. Mistake 3: Overlapping conditions CASE WHEN evaluates top-to-bottom and stops at the first match. Put your most specific conditions first (highest thresholds), then work down. Overlapping conditions create misclassified rows. Try This at Your JobPick your most important table (customers, orders, users) and build one segmentation:
This is one of the most frequently requested analyses in any business. Once you build it, you'll use it constantly. Until next time, Brian P.S. Customer segmentation is a core skill in Module 2 (The Marie Kondo Blueprint) and Module 6 (The So What Framework) of SQL for Business Impact. The course teaches you to build segments that drive decisions, not just organize data. Check it out at sqlforbusinessimpact.com. P.P.S. What's the most useful customer segment you've built at work? Hit reply. I'd love to hear how you're using this pattern. 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.
Hey Reader -- I'm trying something new this week! Can you take a minute to fill out this quick survey? Thanks in advance! Okay, on to this week's topic: A common question I get from readers is some version of: "This Summit Adventures stuff is great, but I work in healthcare (or SaaS, or retail, or finance). How does this apply to me?" The honest answer: every SQL pattern you've learned in this newsletter translates directly to your industry. The table names change. So do column names. The...
Hello Reader, Here's a scenario that happens more often than anyone admits: You build a report. Your director uses it in a board presentation. A week later, someone notices the customer count includes 58 records with obviously fake email addresses like evan.clarke743@noemail. The report wasn't wrong. The data underneath it was dirty. And now your credibility takes a hit. Bummer. Not because of your SQL skills, but because you didn't check the final product before sending it off. Data quality...
Hey Reader, Last month, we covered LEFT JOIN to find customers who never booked. That's one type of absence — people who never showed up. But there's another kind that's even more expensive: people who showed up, committed, and then left. The dreaded cancellation. Customers who said "yes", then said "actually, never mind". In the Summit Adventures database (the fake adventure tourism company I created to help people learn business analytics), nearly 47% of all bookings end in cancellation....