SQLQuokka
Start practicing
QuestionsLearnSandboxFeaturesRoadmapFAQ

Amazon: Above City Average Spend

Unsolved

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`.

SQL Query Editor (Ctrl+Enter to run)
0 characters · Valid
Canonical Solution Official

Official Solution is Hidden

Try solving the question with the schema explorer and hints first. When ready, reveal the verified canonical query and step-by-step logic breakdown.

Community Q&A & Discussion

Ask questions, share alternate queries, and explore solutions

0 comments
Asked By:
🏢 Amazon

Submission History

Your recent query executions and answer checks

Execution Pipeline:
FROM customers
Full source dataset
10 rows total
Ready. Type a query to see live execution.
Clause: Auto-Sync · AlaSQL Engine