Use GROUP BY with WHERE to filter and aggregate coupon performance
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.
Each hint you reveal reduces the XP you can earn. Try the query first.
Not every purchase has a coupon. Filter with `WHERE coupon_code IS NOT NULL AND amount > 0` to get only coupon purchases (no refunds)
Group by `coupon_code` and compute `COUNT(*) AS times_used` and `SUM(amount) AS total_revenue`
Use `ROUND(SUM(amount)::numeric, 2) AS total_revenue` to keep revenue clean. Sort by total_revenue DESC to see the best performers