Custom Category Buckets
Segment numerical data into business tiers like High, Medium, and Low with CASE WHEN.
Why this matters
Reports often need labels like High, Medium, and Low. CASE WHEN builds them inside the query, with no spreadsheet work.
Build Tiers in the Query
You do not need to sort numbers by hand in Excel. CASE WHEN builds labels like High and Medium right inside your query.
In real life: CASE WHEN is SQL's if-then. SQL tests each WHEN in order and uses the first one that is true.
Always Add an ELSE
Rows that match no WHEN become blank (NULL) if you leave out ELSE. Add a fallback, like ELSE 'Standard'.
In real life: A marking scheme that says A, B, or C but forgets the "fail" case leaves some pupils with no grade. ELSE makes sure every row gets a label.
End With AS and a Name
Finish with END AS order_tier. This gives the new column a clear name that others can read.
In real life: A column with no title is confusing. END AS order_tier is the title that tells the next person what the column means.
Your practice task
Segment orders into business tiers: mark amounts of 500 or more as 'High', amounts of 100 or more as 'Medium', and everything else as 'Standard', labeled AS order_tier.
How to do it
- Write down the three tiers and their limits.
- Check the biggest limit first, then the next.
- Decide the label for everything left over.
- Name the new column as the brief says, then press Run proof.
Practice it for free in the app. You get instant checks that show what you got right and what to fix. A lesson takes about two minutes and you can try as many times as you like.
Quick reference: Conditional Tier Bucket
The standard SQL technique for customer segmentation and cohort analysis.
SELECT customer_id,
CASE
WHEN spend >= 1000 THEN 'VIP'
WHEN spend >= 250 THEN 'Regular'
ELSE 'Occasional'
END AS customer_tier
FROM customer_stats;More lessons in this course
- Month-by-Month Trends & SQL DialectsGroup timestamps into uniform monthly buckets using DATE_TRUNC or strftime across different SQL dialects.
- Finding Top PerformersRank and retrieve top-N records without pulling millions of unnecessary rows.
- Crash-Proof DivisionPrevent query crashes and broken dashboards by guarding against division by zero and preserving decimal precision.