How would you calculate running total in a transaction table
Asked in the Round 1 stage and asked to write SQL code. A reported follow-up was: How do you handle deposits and withdrawals in running total logic with syntax.
account_id, transaction_id, occurred_at, transaction_type, amount, signed_amount, and running_total.account_id, occurred_at, and transaction_id.| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| account_id | INT | Account associated with the transaction |
| occurred_at | TIMESTAMP | Timestamp when the transaction occurred |
| transaction_type | VARCHAR(20) | Transaction direction, either deposit or withdrawal |
| amount | DECIMAL(12,2) | Transaction amount |
| currency | VARCHAR(3) | ISO currency code |