Code Room
Vibe codingMediumvc-g094
Subject Ai code reviewLevel Mid–Senior~16 minCommon in Databases & SQL · Code quality & review interviewsIndustries Software development

Question

An AI assistant wrote this query to report each customer's lifetime revenue. The reviewer ran it on staging (a few hundred orders) and the numbers looked right, so it shipped. On the production warehouse, totals are inflated 3-8x for high-value customers.

sql
SELECT c.id,       c.name,       SUM(o.amount) AS lifetime_revenue,       COUNT(r.id)  AS refund_countFROM customers cJOIN orders   o ON o.customer_id = c.idJOIN refunds  r ON r.customer_id = c.idGROUP BY c.id, c.name;

What is wrong, why did staging hide it, and how would you have caught it before merge?

What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.

Describe your solution

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.