Code Room
Code reviewMedium
Question
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.
Learn the concepts
SELECT p.id, p.name, p.category_id, SUM(oi.qty) AS units_soldFROM products pLEFT JOIN order_items oi ON oi.product_id = p.idLEFT JOIN orders o ON o.id = oi.order_idWHERE oi.qty > 0 AND o.status = 'paid' AND p.discontinued = falseGROUP BY p.id, p.name, p.category_idORDER BY units_sold DESC;Run or narrate your approach, then ask the coach.