Interview Questions/SQL/Monthly Transactions I

Monthly Transactions I

Preview mode. Log in to edit, run, submit, and save progress.

Medium

Monthly Transactions I

You are given a table of financial transactions. Each transaction has a country, a state (either 'approved' or 'declined'), an amount, and a date. Write a SQL query to find for each month and country: the total number of transactions, the number of approved transactions, the total transaction amount, and the total approved transaction amount. Return the result in any order.

Examples

Example 1

Group by month (YYYY-MM) and country. Count all transactions, count approved ones, sum all amounts, sum approved amounts.

Approach hint

Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

query.sql