Monthly Transactions I

4pts
Stripe

Problem Statement

Financial analysts at Stripe need to monitor transaction health across different markets. They require a report that breaks down activity by month and country.

Write an SQL query to find for each month and country:

  1. The number of transactions and their total amount.
  2. The number of approved transactions and their total amount.

Rules:

  • The month should be formatted as YYYY-MM.
  • If the country is NULL, it should still be included as a group.
  • Return the columns: month, country, trans_count, approved_count, trans_total_amount, and approved_total_amount.
  • Results must be sorted by month in descending order, then by country in ascending order.
Tests your understanding of
Basic SQL, Aggregation, Date Functions and Conditional Logic

Input Tables

transactions
id(INTEGER)country(VARCHAR)state(ENUM('approved', 'declined'))amount(INTEGER)trans_date(DATE)
121USapproved10002024-12-18
122USdeclined20002024-12-19
123USapproved20002025-01-01
124DEapproved30002025-01-07

Expected Output

month(VARCHAR)country(VARCHAR)trans_count(INTEGER)approved_count(INTEGER)trans_total_amount(INTEGER)approved_total_amount(INTEGER)
2025-01DE1130003000
2025-01US1120002000
2024-12US2130001000

Tags

MediumBasic SQLAggregationDate FunctionsConditional Logic
15-20 min
64%

Hints