Marketing Analytics Path · Mission 14 of 25Medium

Revenue by state

JOIN customer dimension with purchases for geographic analysis

Back to Marketing Analytics

The Brief

Sarah KimVP of Marketingmarketing-analytics

We're budgeting for regional campaigns. Can you show me the top 5 states by total purchase revenue? I need the state, total revenue, and number of purchases. Positive purchases only.

You'll practice

Geographic analysisJOINs

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` to connect state info with purchase data

Hint 2

Filter `WHERE p.amount > 0`, GROUP BY `c.state`, then `SUM(p.amount)` for revenue and `COUNT(*)` for purchases

Hint 3

Use `ROUND(SUM(p.amount)::numeric, 2) AS total_revenue` and `ORDER BY total_revenue DESC LIMIT 5`