Skip to content

Commit 1111e02

Browse files
authored
Create account-balance.sql
1 parent 4a35b50 commit 1111e02

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

MySQL/account-balance.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Time: O(nlogn)
2+
# Space: O(n)
3+
4+
SELECT account_id, day,
5+
SUM(CASE WHEN type = 'DEPOSIT' THEN amount ELSE -amount END)
6+
OVER (PARTITION BY account_id ORDER BY day) AS balance
7+
FROM Transactions;

0 commit comments

Comments
 (0)