24/30
Part 5 of 5 · The worked exampleLearn

The rows under the GROUP BY show the extra 2500 and every row WHERE drops

Look at the rows the GROUP BY works on, before the WHERE gets to them. The last column is the WHERE's condition on each row:

SELECT c.city, c.name, o.order_id, o.placed_at, o.total_cents, i.qty,
       o.placed_at BETWEEN '2026-03-01' AND '2026-03-31' AS in_range
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id
LEFT JOIN items i ON i.order_id = o.order_id
ORDER BY c.customer_id, o.order_id, i.dish;
citynameorder_idplaced_attotal_centsqtyin_range
AustinAna102026-03-02 12:15250011
AustinAna102026-03-02 12:15250021
AustinAna112026-03-02 19:40180031
AustinBen122026-03-15 08:05180011
BostonCy132026-03-31 20:30150010
BostonCy142026-04-01 09:00210020
DenverDeeNULLNULLNULLNULLNULL

Seven rows from four customers and five orders. Order 10's 2500 appears twice: that's the extra $25.00.

The WHERE keeps the four rows with a 1. It drops Cy's 20:30 order on the boundary, and Cy's April order, as it should. Dee's row gets NULL, so it goes too, and takes Denver with it.