Loading problem...
A payments platform stores incoming transaction events in one relational table:
Transactions(id, country, state, amount, trans_date)
Column details:
Create a monthly reporting view for each (month, country) pair that appears in the data.
For every month and country, compute:
Output requirements:
Supported submission environments:
transactions:
| id | country | state | amount | trans_date |
|----|---------|----------|--------|-------------|
| 1 | US | approved | 700 | 2024-01-05 |
| 2 | US | declined | 300 | 2024-01-11 |
| 3 | US | approved | 500 | 2024-02-02 |
| 4 | FR | approved | 1000 | 2024-02-19 |
| 5 | FR | declined | 120 | 2024-02-22 |[
{"month":"2024-01","country":"US","trans_count":2,"approved_count":1,"trans_total_amount":1000,"approved_total_amount":700},
{"month":"2024-02","country":"FR","trans_count":2,"approved_count":1,"trans_total_amount":1120,"approved_total_amount":1000},
{"month":"2024-02","country":"US","trans_count":1,"approved_count":1,"trans_total_amount":500,"approved_total_amount":500}
]Rows are grouped by month and country. Approved metrics are computed conditionally while total metrics include all rows.
transactions:
| id | country | state | amount | trans_date |
|----|---------|----------|--------|-------------|
| 10 | IN | declined | 200 | 2025-03-01 |
| 11 | IN | declined | 50 | 2025-03-07 |
| 12 | BR | declined | 30 | 2025-03-20 |[
{"month":"2025-03","country":"BR","trans_count":1,"approved_count":0,"trans_total_amount":30,"approved_total_amount":0},
{"month":"2025-03","country":"IN","trans_count":2,"approved_count":0,"trans_total_amount":250,"approved_total_amount":0}
]Declined rows still contribute to trans_count and trans_total_amount. Approved metrics remain zero when no approved rows exist.
transactions:
| id | country | state | amount | trans_date |
|----|---------|----------|------------|-------------|
| 20 | JP | approved | 0 | 2024-12-31 |
| 21 | JP | approved | 1000000000 | 2024-12-15 |
| 22 | JP | declined | 50 | 2024-12-19 |
| 23 | CA | approved | 75 | 2024-12-03 |[
{"month":"2024-12","country":"CA","trans_count":1,"approved_count":1,"trans_total_amount":75,"approved_total_amount":75},
{"month":"2024-12","country":"JP","trans_count":3,"approved_count":2,"trans_total_amount":1000000050,"approved_total_amount":1000000000}
]The query must correctly handle zero and very large amounts while preserving per-country grouping within the same month.
Constraints