Code Room
Code reviewHardcr-g638
Subject Sql join correctnessLevel Mid–Senior~25 minCommon in Databases & SQL · Distributed systems · Code quality & review interviewsIndustries Software development

Question

Review this SQL that reports revenue per customer.

Each order has multiple payments and each customer has many orders.

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.

Talk through your review
Code to reviewsql
SELECT c.id,       c.name,       SUM(o.amount)      AS revenue,       COUNT(p.id)        AS payment_countFROM customers cJOIN orders   o ON o.customer_id = c.idJOIN payments p ON p.customer_id = c.idWHERE o.created_at >= '2026-01-01'GROUP BY c.id, c.name;
Run or narrate your approach, then ask the coach.