Plate 08
Proof Room Instructor
RareThis is page four. Line one of mine says: starts at the beginning, which is rarer than you think. The chart behind me is yours. You wanted the customers who cleared 100.00 of shipped revenue. SUM in the WHERE, and the database refused you outright, which was kind of it. So you moved the whole condition into HAVING, and it stopped complaining and told you three. The answer is two. Customer 2 only clears the bar on a cancelled order worth 300.00. The question has two filters in it, not one. Shipped belongs in WHERE, which removes rows before the sum. The 100.00 belongs in HAVING, which removes groups after.
Margin note
Same filter, two clauses, two different answers
SELECT customer_id, SUM(order_total) AS revenue
FROM orders
GROUP BY customer_id
HAVING SUM(order_total) > 100
ORDER BY customer_id;
WHERE is evaluated before grouping and cannot reference an aggregate; HAVING is evaluated after. This question needs both clauses: status = ‘shipped’ in WHERE so the cancelled row never enters the sum, and SUM(order_total) > 100 in HAVING so the group is judged after it. Customer 2 clears 100.00 only on a cancelled order of 300.00.
Executed against DuckDB 1.5.3-r.3, 2026-09-05 · companion file: aimi-companion.sql