0
← Exercises/
Window Functions•13 of 14
Window FunctionsAdvancedPRO

Real-Time Account Ledger Running Balance

Scenario

Core banking ledgers process deposits (positive credits) and debits (negative withdrawals). Financial auditors require computing the exact balance of each bank account after every transaction.

Task
For each transaction in `account_ledger_lines`, compute the real-time running balance for that specific account. Return: 1. `line_id` 2. `account_id` 3. `amount` 4. `running_balance`: Cumulative sum of `amount` partitioned by `account_id` ordered by `line_id ASC` Order results by `account_id` ascending, then by `line_id` ascending.
Expected Output Format

Ledger lines showing running balance per account.

Input Tables & Sample Data0 tables
Loading database schema...
Need a hint?
query.sql|Local Sandbox
Loading SQL editor...
Click "Run" or press ⌘ + Enter to execute your query

About the “Real-Time Account Ledger Running Balance” SQL Problem

Business Scenario

Core banking ledgers process deposits (positive credits) and debits (negative withdrawals). Financial auditors require computing the exact balance of each bank account after every transaction.

Expected Output & Criteria

Ledger lines showing running balance per account.

Database Table Schema (PostgreSQL DDL)

PostgreSQL 16 WASM

This challenge executes directly against the following relational schema in your browser:

CREATE TABLE account_ledger_lines (
        line_id INT PRIMARY KEY,
        account_id INT NOT NULL,
        amount NUMERIC(10, 2) NOT NULL
      );

Target SQL Clauses & Operators

SUMOVERPARTITION BY

Want more Window Functions practice?

Explore the full syllabus of 14 exercises, syntax guides, and interview pitfalls.

View Window Functions Track→