Derive Daily Closing Balances From a Transaction Ledger

Last updated: November 29, 2026

Quick Overview

Given an account opening-balance table and a posted transactions table, write SQL that returns every account's closing balance for every calendar day in a date range, including days with no activity.

Citi
Data Manipulation (SQL/Python)
Data Engineer
Citi
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given an account opening-balance table and a posted transactions table, write SQL that returns every account's closing balance for every calendar day in a date range, including days with no activity.

Citi's data engineering teams build balance and liquidity reporting for treasury clients and regulators, where a missing day is a reporting defect. The screen checks window functions, date spines and whether you notice that quiet days still need a balance.

What the Interviewer Expects
  • Build a date spine and cross join with accounts
  • Aggregate transactions to one net amount per account per day
  • Use a running SUM window ordered by date
  • Add the opening balance
  • Explain why a LEFT JOIN plus COALESCE is needed
Key Topics to Cover
window functions
date spine
running totals
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 handle back-valued transactions that post today with an earlier value date?
  • How would you make this incremental instead of recomputing history every night?
  • What changes for multi-currency accounts reported in USD?
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, opening_date) and transactions(txn_id, account_id, value_date, amount) where amount is signed (credits positive). Report range is 2026-01-01 to `2026-01-3...

Approach
  1. Generate one row per day in the range (a date spine).
  2. Cross join it with accounts so every account has every day.
  3. Sum transactions per account per day.
  4. Left join, coalesce missing days to ...

Submit Your Answer
Markdown supported

Related Questions