Code RoomWHERE clause filters zero sales
MediumPrep Room Coding #1838

WHERE clause filters zero sales

Code reviewDatabases & SQLMid–Senior~20 min

Review this SQL reporting query that should list every active product with its total units sold (including products that sold zero).

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1SELECT p.id,
2 p.name,
3 p.category_id,
4 SUM(oi.qty) AS units_sold
5FROM products p
6LEFT JOIN order_items oi ON oi.product_id = p.id
7LEFT JOIN orders o ON o.id = oi.order_id
8WHERE oi.qty > 0
9 AND o.status = 'paid'
10 AND p.discontinued = false
11GROUP BY p.id, p.name, p.category_id
12ORDER BY units_sold DESC;
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.