Your question is Top Users by Spend. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
The v4c.ai workspace team wants to identify its highest-spending users. Write a PostgreSQL query that calculates each user's total purchase spend and returns the top three users.
user_id as a deterministic tie-breaker when total spend is equal. Transactions with a NULL amount should not increase spend, and purchases that do not match a user should not appear in the result.| Column | Type | Description |
|---|---|---|
| user_idPK | INTEGER | Unique user identifier |
| user_name | VARCHAR(100) | User's display name |
| Column | Type | Description |
|---|---|---|
| purchase_idPK | INTEGER | Unique purchase identifier |
| user_id | INTEGER | User associated with the purchase |
| amount | DECIMAL(10,2) | Purchase amount |