Your question is Top Spending Categories Query. 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.
ING wants a quarterly view of spending patterns among customers who were active during the most recent completed quarter. For this exercise, treat Q2 2025 as the reporting quarter, from 2025-04-01 inclusive through 2025-07-01 exclusive.
Write a PostgreSQL query to identify the three highest-spending transaction categories for ING users whose last_active_at falls within Q2 2025. Include only transactions occurring in the same quarter. Treat NULL transaction amounts as contributing zero, exclude transactions without a category, and calculate net spending by summing transaction amounts.
| Column | Type | Description |
|---|---|---|
| user_idPK | INTEGER | Unique ING customer identifier |
| full_name | VARCHAR(100) | Customer name |
| last_active_at | DATE | Date of the customer's most recent activity |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INTEGER | Unique transaction identifier |
| user_id | INTEGER | Customer who made the transaction |
| transaction_date | DATE | Date of the transaction |
| category | VARCHAR(50) | Spending category |
| amount | NUMERIC(12,2) | Net transaction amount, including refunds |