account_id
and day
columns from the Transactions
table.CASE
statement to determine the signed amount of each transaction (positive for 'Deposit', negative for 'Withdraw').SUM
window function to calculate the running total of the signed amounts, partitioned by account_id
and ordered by day
.balance
.account_id
and day
.erDiagram Transactions { int account_id date day ENUM type int amount account_id_day PK }