Compute Running Balances and First Overdraft Date per Account

Last updated: November 29, 2026

Quick Overview

Given an accounts table with opening balances and a bank transactions table, write SQL that returns, for each account, the running balance after every transaction and the first date the balance went negative, if ever.

Intuit
Data Manipulation (SQL/Python)
Data Engineer
Intuit
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


Given an accounts table with opening balances and a bank transactions table, write SQL that returns, for each account, the running balance after every transaction and the first date the balance went negative, if ever.

Cash flow visibility for small businesses is central to QuickBooks and to Intuit's money products, and analysts and data engineers are expected to be fluent with window functions over ledger data. The interviewer checks ordering of the running sum, tie-breaking within a day, and that accounts that never overdraw still show up.

What the Interviewer Expects
  • Use SUM() OVER with an explicit ORDER BY and a deterministic tie-breaker
  • Add the opening balance correctly
  • Use ROWS rather than the default RANGE frame so same-timestamp rows do not collapse
  • Keep accounts that never overdraw with a NULL first overdraft date
  • Explain how to check the result against a known ending balance
Key Topics to Cover
window functions
running totals
window frames
LEFT JOIN
ledger data
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you compute the number of days each account spent below zero?
  • How would you do this incrementally for millions of accounts each night?
  • Pending versus posted transactions disagree. Which should drive the balance and why?
  • How would you find the lowest balance each account reached in each month?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

accounts(account_id, opening_balance_cents, opened_at) and bank_txns(txn_id, account_id, posted_at timestamp, amount_cents) where debits are negative. I will ask whether txn_id increases with ar...

Approach
  1. Running balance: opening balance plus a cumulative sum ordered by (posted_at, txn_id) with a ROWS frame. The default RANGE frame would give every row with an identical timestamp the same tota...

Submit Your Answer
Markdown supported