runtime
85 / 88

task LEFT JOIN · medium

Capacity 2: retain missing and unmapped sites

Report every site, its region name (NULL for unmapped sites), and active capacity on the snapshot date. Missing active capacity is zero. Order by site id.

what to return

Columns
site_idregionunits in this order
Rows
4 rows · in the order asked
Watch for
Every stage runs on a fresh database; earlier queries do not carry forward.
One unit is one compute unit. Snapshot date: 2026-04-01. Capacity intervals include valid_from and exclude valid_to; NULL valid_to means no end.
Future supply is incremental capacity, available on delivery_date. The snapshot excludes same-day deliveries, so projections add them once.
Skill
Produce reproducible capacity reports with explicit units, dates and grain. Refresher: Multi-grain joins without fan-out →

expected result

Your query should return exactly these columns and values. Run it and compare.

expected result4 rows · in this order
site_idregionunits
1North40
2North40
3South0

first 3 of 4 rows

data you can query

Sample rows from each table. Each column shows its type underneath; → marks a link to another table.

capacity_regions2 columns · 3 rows
idinteger · keynametext
1North
2South
3West

all 3 rows

capacity_sites3 columns · 4 rows
idinteger · keyregion_idinteger → capacity_regionsnametext
11Alder
21Birch
32Cedar
4NULLDrift

all 4 rows

current_capacity5 columns · 5 rows
idinteger · keysite_idinteger → capacity_sitesunitsintegervalid_fromtextvalid_totext
11402026-01-01NULL
22402026-01-01NULL
33992025-01-012026-04-01
4152026-05-01NULL
54102026-01-01NULL

all 5 rows

future_supply4 columns · 6 rows
idinteger · keysite_idinteger → capacity_sitesunitsintegerdelivery_datetext
1172026-04-10
2182026-04-10
31202026-05-01
4252026-04-30
53122026-04-01

showing 5 of 6 rows

solution.sql
 

Hints and the answer are always available. Using them counts the question as solved with help.