Marketing Analytics Path · Mission 13 of 25Medium

Top 5 customers by spend

JOIN dimension and fact tables with aggregation and LIMIT

Back to Marketing Analytics

The Brief

Marcus BellHead of Growthanalytics-help

Who are our biggest spenders? Pull the top 5 customers by total spend. I need their customer_id, first_name, last_name, and total amount spent. Exclude refunds.

You'll practice

Multi-table JOINLIMIT

Tables available

dim_customersfact_purchases

Hints (3)

Each hint you reveal reduces the XP you can earn. Try the query first.

Hint 1

JOIN `dim_customers` to `fact_purchases` on `customer_id`, then filter `WHERE p.amount > 0` to exclude refunds

Hint 2

GROUP BY customer_id, first_name, last_name and use `SUM(p.amount) AS total_spent`

Hint 3

Sort with `ORDER BY total_spent DESC LIMIT 5` to get the top 5 spenders