Practice · medium · dataset: ecom
Customer revenue without fan-out
Finance wants total revenue and order count per customer. Revenue is the sum of line values
(quantity times the line’s unit_price).
Return customer_id, email, order_count, and revenue rounded to two decimals. Sort by
revenue descending, then by customer_id ascending.
Tables available
| Table | Columns |
|---|---|
customers |
customer_id, email, country, signup_date |
orders |
order_id, customer_id, order_date, status, channel |
order_items |
order_id, product_id, quantity, unit_price |
The order count must be the number of orders, not the number of line items. Customers with no orders should not appear.
⌘/Ctrl + Enter to grade
Write a query, then grade it.
Hints
Try it first. Reveal a hint only when you are stuck.