Write a query to identify the top 5% of users by spend in the last 3 months.
Use the users and payments tables. Spend includes completed payments within the rolling three-month period; users without qualifying payments should be treated as spending zero.
user_id, email, total_spend, and spend_rankspend_rank, then user_id| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique user identifier |
| VARCHAR(255) | User email address | |
| created_at | DATE | Date the user account was created |
| Column | Type | Description |
|---|---|---|
| payment_idPK | INT | Unique payment identifier |
| user_id | INT | User who made the payment |
| amount | DECIMAL(12,2) | Payment amount |
| status | VARCHAR(20) | Payment processing status |
| paid_at | DATE | Payment date |