Difficulty: Intermediate · Estimated time: 15 min Schema:
00_Sample_Schema.sql
Same shape as Lesson 02 (CASE over an aggregate), applied to a
multi-table join across locations → departments. This lesson
focuses on what happens to CASE classification when the underlying
join can fan out or drop rows.
CASE after a GROUP BY that spans two joined tablesJOIN choice (INNER vs LEFT) silently changes classification resultsCASE output to drive business decisions (expansion planning)Expansion and resource-allocation decisions (“should we open a second office in this city?”) are often driven by exactly this kind of department-concentration metric.
See 03_City_Analysis.sql.
COUNT(DISTINCT d.dept_id) > 1 is a binary classifier (High/Low
Demand) — a good reminder that CASE doesn’t need 3+ branches to
be useful; sometimes a clean boolean label is exactly what’s needed
instead of a raw count.INNER JOIN, a city with zero departments (e.g.
a new office location added to locations before any department is
assigned) won’t appear in the result at all — not even as “Low
Demand.” This is the same trap as Lesson 02, worth internalizing
because it recurs constantly in real reporting.CASE threshold is a single cutoff (High vs Low), consider
naming the cutoff as a well-known business term in the alias
(city_status) and documenting the exact number (> 1) in a
comment — thresholds drift, and future maintainers need to know why
1 was chosen, not just that it was.INNER JOIN, cities that never got any department at all are
invisible, which is a different (and often more urgent) business
situation than “low but present.”02_Department_Categorization.md04_Employee_Labelling.md