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.

Your progress0%

0 of 8 concepts completed

Complete the activity and related MCQ to unlock the next concept.

Concept 1WHY CASE

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.

5
CUSTOMERS
2
HIGH VALUE
₹84,000
HIGH TOTAL
idnamecityamountsegment
101RahulDelhi₹52,000High
102PriyaMumbai₹18,000Medium
103AmitPune₹7,500Low
104NehaDelhi₹32,000High
105ArjunMumbai₹4,200Low

Learn by Seeing

Rule → category

CASE

    WHEN amount >= 30000 THEN 'High'

    WHEN amount >= 10000 THEN 'Medium'

    ELSE 'Low'

END

The 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.

01

Read the rule

What are the thresholds?

02

Order branches

Highest threshold first.

03

Add ELSE

Handle unmatched rows.

04

Name it

Use AS to give the result column a clear name.

Lesson Summary

What you learned

CASE WHEN

Apply conditional logic row by row.

WHEN / THEN / ELSE / END

The four keywords that structure a CASE expression.

First-match wins

Order WHEN branches from narrowest to broadest.

Conditional aggregates

SUM(CASE WHEN … THEN 1 ELSE 0 END) counts, and with amount it sums.

Frequently Asked Questions

SQL CASE WHEN — FAQs