Track 0/9 (0%)
Module 02 · Expressions~12 min · 3 worked queries
Row Expressions, CASE & NULL Recovery
Derive clean categorical labels, normalize strings, and substitute fallback values with COALESCE at row evaluation time.
Scalar expressions — CASE, COALESCE, string normalization, arithmetic — evaluate cleanly per tuple without collapsing rows.Module 02 · Expressions · Reading Room
Mental Model
- 01.
Searched CASE expressions evaluate WHEN branches strictly in written order and stop at the first match.
- 02.
COALESCE returns its first non-NULL argument, turning unpredictable missing values into explicit sentinel defaults.
- 03.
String helpers (LOWER, UPPER, LENGTH, TRIM) transform projection values or normalize predicate comparisons.
Interactive Module Lab · Expressions
9. CASE: if/else inside SQL — sqlSELECT name, salary,CASEWHEN salary >= 130000 THEN 'Senior'WHEN salary >= 90000 THEN 'Mid'ELSE 'Junior'END AS levelFROM usersORDER BY salary DESC;
Execution Stages3 steps
Stage 01 · FROM
10 in → 10 outSOURCE: USERS
Scanned 10 rows from table 'users'.
| # | id | name | department_id | role | salary | state |
|---|---|---|---|---|---|---|
| 1 | 1 | Alice Smith | 1 | Software Engineer | 95,000 | keep |
| 2 | 2 | Bob Jones | 2 | Product Manager | 110,000 | keep |
| 3 | 3 | Charlie Lee | 1 | Software Engineer | 88,000 | keep |
| 4 | 4 | Diana Prince | 3 | UX Designer | 76,000 | keep |
| 5 | 5 | Evan Wright | 2 | Data Analyst | 82,000 | keep |
| 6 | 6 | Fiona Gallagher | 1 | Tech Lead | 135,000 | keep |
| 7 | 7 | George Clark | NULL | Intern | 42,000 | keep |
| 8 | 8 | Hannah Abbott | 2 | Scrum Master | 89,000 | keep |
Inspect each evaluated clause in 9. CASE: if/else inside SQL or animate every row moving between stages in Studio.Open 9. CASE: if/else inside SQL in Studio →