A fintech startup needs to display the current net balance for all users. The ledger records every transaction: credits are stored as positive numbers and debits are stored as negative numbers.
Your task is to write a query that calculates the final balance for each account.
| transaction_id(INTEGER) | account_id(INTEGER) | amount(DECIMAL) | transaction_date(DATE) |
|---|---|---|---|
| 1 | 1001 | 500 | 2026-01-01 |
| 2 | 1001 | -200 | 2026-01-02 |
| 3 | 1002 | 1000 | 2026-01-01 |
| 4 | 1001 | 150 | 2026-01-05 |
| 5 | 1002 | -1100 | 2026-01-10 |
| account_id(INTEGER) | account_name(VARCHAR) | account_type(VARCHAR) |
|---|---|---|
| 1001 | Alice Green | Savings |
| 1002 | Bob White | Checking |
| branch_id(INTEGER) | branch_name(VARCHAR) |
|---|---|
| 1 | Downtown |
| 2 | Uptown |
| account_id(INTEGER) | account_name(VARCHAR) | final_balance(DECIMAL) |
|---|---|---|
| 1001 | Alice Green | 450 |
| 1002 | Bob White | -100 |