Skip to content

2066. Account Balance 👍

1
2
3
4
5
6
7
8
9
SELECT
  account_id,
  day,
  SUM(IF(type = 'Deposit', amount, -amount)) OVER(
    PARTITION BY account_id
    ORDER BY day
  ) AS balance
FROM Transactions
ORDER BY 1, 2;