Hirebeat wants to identify its highest-spending users in each country. Write a PostgreSQL query that calculates each user's total purchase spend, ranks users within their country, and returns the top three users per country.
0.user_id.| Column | Type | Description |
|---|---|---|
| user_idPK | INTEGER | Unique Hirebeat user identifier |
| user_name | VARCHAR(100) | User display name |
| country | VARCHAR(50) | User country |
| Column | Type | Description |
|---|---|---|
| purchase_idPK | INTEGER | Unique purchase identifier |
| user_id | INTEGER | Identifier of the purchasing user |
| amount | NUMERIC(10,2) | Purchase amount |