Regional marketing teams target high-value buyers relative to their geographic peer groups. Write a query to find all customers whose total lifetime spend exceeds the average total spend of all purchasing customers residing in their own city. Return `customer_id`, `customer_name`, `city`, `total_spend`, and `avg_city_spend` (rounded to 2 decimal places). Order the results by `city ASC`, then `total_spend DESC`, and finally `customer_id ASC`.
Loading…
Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.
Ask questions, share alternate queries, and explore solutions
Your recent query executions and answer checks
This will insert the verified MySQL solution into your editor so you can study how each clause transforms the table.