TheAnalyst / SQLAll lessons ↗
Day 7 · Core SQL · 10–20 minutes

CASE expressions

CASE converts conditions into labels or calculated categories.

01 · Learn

The idea

CASE converts conditions into labels or calculated categories. Read the query line by line and identify the input table, the transformation, and the shape of the result before running it.

SELECT order_id, amount, CASE WHEN amount >= 2000 THEN 'Large' ELSE 'Standard' END AS order_size FROM orders ORDER BY order_id;
Read it actively

Before running the example, predict the output columns and whether the query returns one row, many rows, or possibly no rows.

02 · Recall

Explain it without looking

In your own words, explain the main SQL feature in today’s lesson and why it answers the question.

03 · Solve

Run your own query

Label each order Large when amount is at least 2000, otherwise Standard.

Loading browser SQL engine…
04 · Repeat

Close the loop