Ledger Running Balance
ledger_entries holds credits (positive amount) and debits (negative amount) for each account. Several entries can share a date; within a date, entries apply in entry_id order.
For every entry, show the account's running balance after that entry, rounded with ROUND(x, 2).
Return columns account_id, entry_date, entry_id, running_balance. Order by account_id, then entry_date, then entry_id, all ascending.
Schema
CREATE TABLE ledger_entries ( entry_id INTEGER PRIMARY KEY, account_id INTEGER NOT NULL, entry_date TEXT NOT NULL, amount REAL NOT NULL );
Sample data
ledger_entries
| entry_id | account_id | entry_date | amount |
|---|---|---|---|
| 1 | 100 | 2026-01-01 | 1000 |
| 2 | 100 | 2026-01-03 | -250 |
| 3 | 200 | 2026-01-02 | 500 |
| 4 | 100 | 2026-01-05 | -100.5 |
| 5 | 200 | 2026-01-04 | -600 |
| 6 | 200 | 2026-01-06 | 300 |
Hint 1
SUM(...) OVER (PARTITION BY account ORDER BY ...) gives a cumulative sum per account.
Hint 2
An entry_id can be smaller than an earlier-dated entry, so order the window by date first, then id.
Good practice for: Data Analyst, Backend Developer, Data Engineer, Database Administrator
Run checks your query on the sample data (Ctrl + '). Submit also checks hidden databases.