29. SQL for Excel Users (Term Map + Side-by-Side)
29.4 CASE WHEN = IF / IFS
Why. IF / IFS in Excel = CASE WHEN in SQL.
What. Same rule engine; SQL keeps the rule next to the data.
How. Translate one IFS into CASE on order size.
Steps
- Write IFS in Excel words.
- Write CASE WHEN.
- Compare labels on the same amounts.
Examples
Example 1 · dataset: raja_coffee
SELECT amount_inr,
CASE WHEN amount_inr >= 1000 THEN 'Large'
WHEN amount_inr >= 600 THEN 'Medium'
ELSE 'Small' END AS size
FROM orders
LIMIT 6;Output
| amount_inr | size |
|---|---|
| 840.0 | Medium |
| 720.0 | Medium |
| 890.0 | Medium |
| 1050.0 | Large |
| 620.0 | Medium |
| 890.0 | Medium |
Meaning. IFS twin.
Ravindra Bagale's Tip
Prefer CASE in SQL over exporting to Excel just to IF-label.
Ravindra Bagale's Tip – मराठी
फक्त IF-लेबलसाठी Excel export करण्यापेक्षा SQL मध्ये CASE.
Ravindra Bagale's Tip – हिंदी
सिर्फ IF-लेबल के लिए Excel भेजने से बेहतर SQL में CASE।