RienSQL
TASK #224 · Medium · Santander

Month-over-Month Change in Charges

Your brief
Santander compares the total of charges (tx_type = 'cargo') across all accounts in a month with the previous month's total.

Write a query that, for each month with charges, returns mth in the 'YYYY-MM' format, the total of charges total_charges, the previous month's total prev_total and the percentage change change_pct = (total_charges − prev_total) × 100 / prev_total, rounded to two decimals. For the first month prev_total and change_pct are NULL. Sort the result by mth.
Expected columnsmth total_charges prev_total change_pctSantander
SQL editor
SQLite
Ctrl / ⌘ + ↵
Result

Write a query and run it to see the results.

Schema
customerscustomer_id, full_name, city
accountsaccount_id, customer_id, account_type, balance, overdraft_limit
transactionstransaction_id, account_id, tx_date, tx_type, amount, description