SQL Data Analytics • Lesson 9
CASE WHEN & Conditional Analysis
Learn how SQL turns raw numbers into meaningful business categories using CASE WHEN — and how to combine CASE with aggregate functions.
0 of 8 concepts completed
Complete the activity and related MCQ to unlock the next concept.
Turn Numbers into Business Meaning
A database may store a customer spending ₹52,000, but a business report needs a meaningful label like 'High Value'. CASE WHEN lets SQL apply rules and create a calculated category.
Interactive Data
Customers table
We use the same five customers throughout the lesson so you can see how the CASE rules classify each one.
| id | name | city | amount | segment |
|---|---|---|---|---|
| 101 | Rahul | Delhi | ₹52,000 | High |
| 102 | Priya | Mumbai | ₹18,000 | Medium |
| 103 | Amit | Pune | ₹7,500 | Low |
| 104 | Neha | Delhi | ₹32,000 | High |
| 105 | Arjun | Mumbai | ₹4,200 | Low |
Learn by Seeing
Rule → category
CASE
WHEN amount >= 30000 THEN 'High'
WHEN amount >= 10000 THEN 'Medium'
ELSE 'Low'
ENDThe CASE expression evaluates the amount and returns a business-friendly segment.
Interactive Activity
What does CASE WHEN mainly do?
Hint: Think about turning a numeric amount into a category label.
SQL Analyst Mindset
Business rules → SQL categories
Most business questions are not about raw numbers, they are about classification. CASE WHEN is how analysts translate a policy like "High ≥ 30,000" into a real SQL column.
Read the rule
What are the thresholds?
Order branches
Highest threshold first.
Add ELSE
Handle unmatched rows.
Name it
Use AS to give the result column a clear name.
Lesson Summary
What you learned
Apply conditional logic row by row.
The four keywords that structure a CASE expression.
Order WHEN branches from narrowest to broadest.
SUM(CASE WHEN … THEN 1 ELSE 0 END) counts, and with amount it sums.
Frequently Asked Questions