|
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 doesn't come pre-labeled. Your database stores numbers: total spent, number of bookings, days since last purchase. But your marketing team needs categories: "VIP," "At-Risk," "New Customer." How to Create Categories That Don't Exist YetHere's what I ran against the Summit Adventures database (the fake adventure tourism company I created to help people learn business analytics):
Here's the tier distribution for Summit Adventures:
The VIP tier (roughly 9% of customers) likely generates over 40% of total revenue. That's the 80/20 rule. Marketing should treat these customers very differently from occasional buyers: dedicated account management, early access to new expeditions, and personalized outreach. How CASE WHEN WorksThink of CASE WHEN like an if/then decision tree:
Important: CASE WHEN evaluates top to bottom and stops at the first match. That's why we start with the highest tier ($5,000+) and work down. If a customer spent $7,000, they match the first condition and get labeled "VIP" ... it never checks the lower tiers. You Don't Need Excel For ThisWithout CASE WHEN, creating segments means:
With CASE WHEN: Segments are built directly in your query. They update automatically every time you run it. No manual maintenance. Four Different Ways To Use SQL Case Statements1. Customer Engagement Tiers
2. Booking Size Categories
3. Promo Code Effectiveness
4. Geographic Regions
Combining CASE WHEN With GROUP BYHere's where it gets really useful. You can group by your new segments:
This gives you a summary table showing how many customers are in each tier, total revenue per tier, and average spend. That's the kind of breakdown your marketing director can act on immediately. Nice job! The Pattern to Remember
Start with the highest value and work down. Always include ELSE for anything that doesn't match. Name the column something business-friendly (Not "case_result". Use "spending_tier" or "engagement_status"). Try This At Your JobThink about the raw data sitting in your company's database right now. What labels would make it more useful?
Any time you need to turn continuous numbers into meaningful business categories, CASE WHEN is the tool. Hope this was useful! Hit reply and let me know. Until next time, Brian P.S. Customer segmentation is one of the most practical SQL skills you can develop. It's covered throughout SQL for Business Impact, especially in Module 2 where we use the Marie Kondo Blueprint to organize and filter data. Check it out at sqlforbusinessimpact.com. P.P.S. What segments would be most useful at your company? Reply and tell me. I'm always looking for real-world examples to feature in future emails. 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, This week's newsletter is different. Not a regular "how to solve problem X with SQL" kinda thing. Because I've realized something: you can write perfect queries and still never get the career impact you want. You need "soft skills" like presenting your results to leadership in addition to "technical skills" like using CTEs and WINDOW functions. Let me show you what I mean. The Scenario Wednesday, 2pm. Q2 review meeting. CMO: "Our booking conversion is down. What's causing it?"...
Hello Reader, Imagine this scenario: Your CMO walks into Monday's meeting with a question: "I need to see our top 3 highest-revenue expeditions in EACH category - hiking, climbing, safari, cultural, and photography." Most analysts would write 5 separate queries, one per category. Or export to Excel and manually filter. An hour of work, minimum. Confident analysts write one query using window functions. Takes 3 minutes. Here's the skill that separates intermediate analysts from advanced ones....
Hello Reader, One thing before we get into this week's tutorial on the magic of JOINs: I launched a new job board -- just for data people! 🥳 It's called DataJobsOnline.com (creative, I know). And I have been building out the data base of jobs over the past few weeks: 405 Remote Data Analyst Jobs 182 Mid-Level Jobs that require "SQL" 183 Tableau Jobs 38 Data Jobs in London You get the idea...it's a job board! For data professionals like you. If you're not job hunting right now, but know...