Stripe operates a global payment processing network. A key metric for risk management is the chargeback rate and value relative to approved transactions.
A chargeback happens when a customer disputes a transaction after it has occurred. Even if a transaction was approved in a previous month, a chargeback is recorded based on the date it was filed.
Write an SQL query to find for each month and country:
- The number of approved transactions and their total amount.
- The number of chargebacks and their total amount.
Rules:
- Output columns: month, country, approved_count, approved_amount, chargeback_count, chargeback_amount.
- month should be in YYYY-MM format.
- Only include months where there is at least one approved transaction or one chargeback.
- Results must be sorted by month in ascending order, then by country in ascending order.