Given a massive table of user transactions, write a query to find the top 3 highest-spending users in each region over the last 30 days.
Use the users and transactions tables. The 30-day window is relative to CURRENT_DATE; exclude users without a region and transactions outside the window.
region, user_id, user_name, total_spent, and spending_rank.user_id as the tie-breaker.region, then spending_rank.| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique user identifier |
| user_name | VARCHAR(100) | User display name |
| region | VARCHAR(50) | User's geographic region |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| user_id | INT | User associated with the transaction |
| transaction_date | DATE | Date on which the transaction occurred |
| amount | NUMERIC(12,2) | Transaction amount |