Paths Subjects Questions Quizzes Pricing Search
Beginner Open Pro

A Report's Revenue Numbers Are Mysteriously Too High

A finance analyst reports that a daily revenue-by-region report is showing numbers roughly 2-3x too high compared to the source system. The query looks like this:

SELECT
  c.region,
  SUM(o.amount) AS total_revenue
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
LEFT JOIN order_line_items li ON o.order_id = li.order_id
GROUP BY c.region;

Each orders row has a total amount, and each order can have multiple rows in order_line_items (one per product in the order). The analyst insists the query "looks right" because every JOIN correctly matches on a real foreign key with no typos.

  1. Diagnose exactly why SUM(o.amount) is inflated, reasoning about row counts the way this subject teaches (not just "joins are tricky").
  2. Propose two different fixes, and explain the trade-off between them.
  3. Suppose you didn't have this line-item detail and just needed to sanity check whether a JOIN is inflating row counts before trusting any aggregate built on top of it — describe a concrete, generic technique for catching this class of bug before it reaches a report.

Share this question

← Back to SQL Mental Model & Query Execution Order practice

We use cookies for product analytics to improve OmniAtlas. See our Privacy Policy.