TASK #224 · Medium · SantanderMonth-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.
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.
Ctrl / ⌘ + ↵
Result
Write a query and run it to see the results.
Schema
customerscustomer_id, full_name, cityaccountsaccount_id, customer_id, account_type, balance, overdraft_limittransactionstransaction_id, account_id, tx_date, tx_type, amount, description