Brex finance teams need a recent view of company spending by category. Write a PostgreSQL query that finds the top three categories for each company using net spend after refunds, evaluated as of 2025-03-31.
net_spend as transaction amount minus refunded amount.| Column | Type | Description |
|---|---|---|
| company_idPK | INT | Unique Brex customer company identifier |
| company_name | VARCHAR(120) | Company display name |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique card transaction identifier |
| company_id | INT | Company associated with the transaction |
| category | VARCHAR(80) | Spending category |
| amount | NUMERIC(12,2) | Original positive transaction amount |
| transaction_date | DATE | Date the transaction posted |
| Column | Type | Description |
|---|---|---|
| refund_idPK | INT | Unique refund identifier |
| transaction_id | INT | Transaction receiving the refund |
| amount | NUMERIC(12,2) | Refund amount |
| refunded_at | DATE | Date the refund posted |