Using the customer_transactions table, calculate the monthly closing balance for each customer.
Treat txn_amount as positive for rows where txn_type = 'deposito' and negative for all other transactions.
The result must show the columns customer_id, month, and closing_balance, ordered by customer_id, month.
Return only the first 10 rows of the ordered result.
Hints
-
Hint 1
First turn each transaction into a positive or negative value.
deposit increases the balance, the other transaction types decrease it.
-
Hint 2
Extract a YYYY-MM format from txn_date.
Then sum by customer_id and month.
-
Hint 3
The closing_balance is not just the month’s delta.
You need a running total ordered by month for each customer.