Practice — SQL for Data Analysis (6 questions)
Beginner
Open
Free
The Revenue Number That Tripled Overnight Permalink →
An analyst reports total revenue per country using the schema from the
subject (users, events, orders):
SELECT u.country, SUM(o.amount) AS revenue, COUNT(e.event_id) AS events
FROM users u
JOIN orders o ON o.user_id = u.user_id
JOIN events e ON e.user_id = u.user_id
WHERE o.status = 'paid'
GROUP BY u.country;
Finance says the total revenue is roughly 4× the number in the payments dashboard.
- Explain precisely why the revenue is inflated, using a small concrete example (one user, a few orders, a few events).
- Rewrite the query so that both
revenueandeventsare correct, and so that countries whose users have orders but no events still appear. - What quick sanity check would have caught this before the report was sent?
Share this question