AARP Rewards wants to identify the highest-value completed purchases within each user category. Write a PostgreSQL query that joins users to transactions, filters eligible purchases, and returns the top three purchases for every category.
status = 'completed' and a positive, non-null amount.user_category, using purchase amount descending and transaction_id ascending as the deterministic tie-breaker.| Column | Type | Description |
|---|---|---|
| user_idPK | INTEGER | Unique user identifier |
| user_name | VARCHAR(100) | User display name |
| user_category | VARCHAR(30) | AARP Rewards user category |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INTEGER | Unique transaction identifier |
| user_id | INTEGER | User who made the purchase |
| amount | NUMERIC(10,2) | Purchase amount in dollars |
| status | VARCHAR(20) | Transaction processing status |