Marketing Analytics Path · Mission 7 of 25Easy

Which coupon is pulling its weight?

Use GROUP BY with WHERE to filter and aggregate coupon performance

Back to Marketing Analytics

The Brief

Alex ChenMarketing Managerslack-dm

Finance is asking about our coupon codes. Can you show me each coupon code, how many times it was used, and the total revenue from purchases that used it? Only include actual purchases — skip the refunds.

You'll practice

GROUP BYWHERENULL filtering

Tables available

fact_purchases

Hints (3)

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

Hint 1

Not every purchase has a coupon. Filter with `WHERE coupon_code IS NOT NULL AND amount > 0` to get only coupon purchases (no refunds)

Hint 2

Group by `coupon_code` and compute `COUNT(*) AS times_used` and `SUM(amount) AS total_revenue`

Hint 3

Use `ROUND(SUM(amount)::numeric, 2) AS total_revenue` to keep revenue clean. Sort by total_revenue DESC to see the best performers