Layout

Revenue by buyer country

PROBLEM 8 / 24 · BASICAll problems ↗

Calculate completed-order revenue by customer country. Return country and revenue_cents. All orders use USD regardless of customer country; no FX conversion is needed. Row order does not matter.

Outputcountryrevenue_cents

query.sql

DuckDB SQL

Restoring your saved draft…

⌘ / Ctrl + Enter to run

Run a query to see results.

Reveal solution & explanation
SELECT c.country, SUM(o.order_total_cents) AS revenue_cents FROM customers c JOIN orders o ON c.customer_id = o.customer_id WHERE o.status = 'completed' GROUP BY c.country;

The customer join is many orders to one customer, preserving the order grain before aggregation.

Data & schema

customer_id
INTEGER · PK
customer_name
VARCHAR
country
VARCHAR
email
VARCHAR
signup_date
DATE
Table notes & relationships

Buyer accounts. Some buyers have no orders, and some email addresses are NULL.

Fictional teaching data. Money is USD cents; timestamps are UTC.