Flag Budgets That Overran Their Monthly Card Spend Limit
Last updated: November 29, 2026
Quick Overview
Given budgets with monthly limits, cards assigned to budgets, and card transactions (including refunds and pending holds), write a SQL query that lists every budget whose settled net spend for October 2026 exceeded its limit, with the overrun amount and percent used.
Brex
November 29, 20260
0
0 solved
Given budgets with monthly limits, cards assigned to budgets, and card transactions (including refunds and pending holds), write a SQL query that lists every budget whose settled net spend for October 2026 exceeded its limit, with the overrun amount and percent used.
Brex customers set budgets that cards draw from, and finance teams want to see which budgets went over in a closed month. A screen like this checks that a data scientist handles card data correctly: settled versus pending, refunds as negative amounts, and half-open date ranges.
What the Interviewer Expects
- Asks whether pending authorizations and refunds count toward spend
- Filters to settled transactions with a half-open month range
- Aggregates per budget through the card to budget join
- Keeps money in integer cents and computes overrun and percent used
- Returns only budgets strictly over the limit, ordered by overrun
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you include budgets that are at 90 percent or more as a warning tier?
- Transactions arrive in many currencies. Where should FX conversion happen and at which rate?
- A card moved between budgets mid-month. How does your query attribute its spend?
- How would you make this a daily running total so finance sees overruns before month end?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Tables: budgets(budget_id, name, monthly_limit_cents), cards(card_id, budget_id), transactions(txn_id, card_id, amount_usd_cents, status, posted_at). I would confirm:
- Only
SETTLEDrows coun...
Approach
- Filter transactions to settled rows with
posted_at >= '2026-10-01' AND posted_at < '2026-11-01'. The half-open range catches timestamps late on Oct 31 without needing23:59:59. - Join to cards...