Calculating monthly interest for bank account
Question
Suppose you're given the following table showing the monthly change in a bank account for a business:
Table: cash_flows
month | net_account_change |
---|---|
1 | 5000 |
2 | -1000 |
3 | 12000 |
4 | 3000 |
5 | 3000 |
6 | 6000 |
7 | 500 |
8 | 3000 |
9 | 6000 |
10 | 2000 |
11 | -4000 |
12 | 2500 |
The bank account started at $0 and earns an annual interest rate of 3% on the total account balance, paid out monthly (0.25% / month). Given this information, along with the table above, write a SQL query to return the account interest paid out each month. For simplicity, you can assume the cumulative total account balance does not go negative.
You can view/query the data in an interactive SQL fiddle here.