Your question is SQL Top Spending by Month. 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.
Booz Allen Hamilton's Data Science practice needs a monthly view of spending by department. Write a PostgreSQL query that returns the three highest-spending departments for each calendar month.
status = 'completed' and a positive amount.transactions to departments so orphaned department IDs are excluded.| Column | Type | Description |
|---|---|---|
| department_idPK | INT | Unique department identifier |
| department_name | VARCHAR(100) | Department display name |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| department_id | INT | Department associated with the transaction |
| transaction_date | DATE | Date on which the transaction occurred |
| amount | NUMERIC(12,2) | Transaction amount in dollars |
| status | VARCHAR(20) | Transaction processing status |