Fix one thing at a time, and check that each fix moves only what it should
Fix 1, the rows that vanished. Move the date condition into the ON of the orders join, and delete the WHERE:
LEFT JOIN orders o ON o.customer_id = c.customer_id
AND o.placed_at BETWEEN '2026-03-01' AND '2026-03-31'
Fix 2, the boundary. Make the range half-open:
LEFT JOIN orders o ON o.customer_id = c.customer_id
AND o.placed_at >= '2026-03-01'
AND o.placed_at < '2026-04-01'
Fix 3, the fan-out. Bring items to one row per order in a CTE called dishes, join it in place of items, and sum d.dishes.
Fix 4, the blanks. The question asked for zeros, so wrap both sums in COALESCE.
Here's the output after each fix, each one run as a whole query on the fixture:
Each cell is revenue, then dishes:
| After | Austin | Boston | Denver |
|---|---|---|---|
| the generated query | 86.0, 7 | no row | no row |
| 1: range moved into ON | 86.0, 7 | NULL, NULL | NULL, NULL |
| 2: half-open range | 86.0, 7 | 15.0, 1 | NULL, NULL |
| 3: dishes CTE | 61.0, 7 | 15.0, 1 | NULL, NULL |
| 4: COALESCE | 61.0, 7 | 15.0, 1 | 0.0, 0 |
Fix 1 brings every city back, but Boston is still blank: its one March order is outside the range. Fix 2 brings it in. Fix 3 takes the extra 2500 off Austin, and fix 4 turns Denver's blanks into zeros.
After fix 4 the output matches the hand answer, and each fix changed it only where you said it would.
Say it back. It was meant to report March revenue and dishes for every city. It reported revenue only for cities with a March order before the last day, and it counted each order's total once per item line. There were three causes. The item join repeated order totals. The date filter in WHERE threw away the rows the LEFT JOIN added. And BETWEEN with a bare end date cut off the last day. I moved the range into the ON clause as a half-open range, brought items to one row per order before the join, and turned empty sums into zeros.
In the editor, fix CITY_MARCH: the generated query, one fix at a time.