TikTok Shop needs a monthly leaderboard of its highest-spending users. Write a PostgreSQL query that returns the top three users by completed purchase spend for each calendar month.
users to transactions using user_id.status = 'completed' and non-null amounts.user_id.| Column | Type | Description |
|---|---|---|
| user_idPK | INTEGER | Unique user identifier |
| display_name | VARCHAR(100) | User-facing display name |
| VARCHAR(255) | User email address |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INTEGER | Unique transaction identifier |
| user_id | INTEGER | User associated with the transaction |
| purchased_at | TIMESTAMP | Timestamp when the purchase occurred |
| amount | NUMERIC(12,2) | Purchase amount |
| status | VARCHAR(20) | Transaction processing status |