How would you write a SQL query to identify the top 10% of purchasing users by region over the last quarter?
Use the previous completed calendar quarter relative to current_date. Include only completed purchases and users assigned to a recognized region.
region_name, user_id, total_spend, region_user_count, and user_rankregion_name, then user_rank, then user_id| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique purchasing user identifier |
| user_name | VARCHAR(100) | User display name |
| region_id | INT | Assigned region identifier |
| Column | Type | Description |
|---|---|---|
| region_idPK | INT | Unique region identifier |
| region_name | VARCHAR(100) | Region name |
| Column | Type | Description |
|---|---|---|
| purchase_idPK | INT | Unique purchase identifier |
| user_id | INT | User who made the purchase |
| purchased_at | TIMESTAMP | Purchase timestamp |
| amount | NUMERIC(12,2) | Purchase amount |
| status | VARCHAR(20) | Purchase processing status |