Match a job Paths Subjects Questions Quizzes Pricing
Overview Read Practice

Practice — SQL for Data Analysis (6 questions)

Pro content

Sign up free, then start a 14-day Pro trial — no card needed.

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.

  1. Explain precisely why the revenue is inflated, using a small concrete example (one user, a few orders, a few events).
  2. Rewrite the query so that both revenue and events are correct, and so that countries whose users have orders but no events still appear.
  3. What quick sanity check would have caught this before the report was sent?

Share this question

Beginner Open Pro

Users Who Never Purchased Returns Zero Rows

Unlock this question →
Intermediate Open Pro

The Running Total That Jumps in Steps

Unlock this question →
Intermediate Open Pro

Build a Weekly Retention Table

Unlock this question →
Intermediate Open Pro

Sessions from an Event Log, Then a Funnel

Unlock this question →
Intermediate Open Pro

Interview Round: Top-N per Group, Nth Highest, Streaks

Unlock this question →

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