Write a SQL query to find the top 3 users by spend in each month, including ties.
Use the provided users and purchases tables. Calculate each user's total purchase amount per calendar month, include all users whose rank is three or better, and exclude purchases without a matching user.
month, user_id, user_name, total_spend, and spend_rank| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique user identifier |
| user_name | VARCHAR(100) | User display 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(10,2) | Purchase amount |