Ledger Balance as of Date

medium · sql, aggregation, correctness

Ledger Balance as of Date

You are given a double-entry style ledger table with signed amounts.

Schema:

  • accounts(id, name)
  • ledger_entries(entry_id, account_id, entry_ts, amount_cents, status)

Compute each account's balance as of 2025-04-30 using only rows with status = 'posted' and entry_ts <= '2025-04-30'.

Return the columns:

  • account_id
  • balance_cents

Include all accounts, even if the balance is zero. Order by account_id.

Run tests to see results
No issues detected