You are given account transactions and need to produce a row-by-row balance audit for each account. Write a PostgreSQL query that shows each transaction with the prior balance, the balance change from the previous row, and the running balance after the transaction. The logic must work across records in timestamp order, so this is a good test of how you handle row-dependent calculations.
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Primary key for the transaction |
| account_id | INT | Account identifier |
| transaction_ts | TIMESTAMP | Transaction timestamp used for sequencing |
| transaction_type | VARCHAR(20) | Transaction category such as deposit or withdrawal |
| amount | NUMERIC(12,2) | Signed amount applied to the account |
| note | TEXT | Optional note or reason for the transaction |