# Monthly Transactions I LeetCode Solution

This Leetcode problem Monthly Transactions I LeetCode Solution is done in SQL.

# List of all LeetCode Solution

## Problem Statement

id is the primary key of this table. The table has information about incoming transactions. The state column is an enum of type [“approved”, “declined”].

Write an SQL query to find for each month and country, the number of transactions and their total amount, the number of approved transactions and their total amount.

Return the result table in any order.

The query result format is in the following example.

Example 1:
Input:

Output:

## Monthly Transactions I LeetCode Solution MySQL

``````select
date_format(trans_date, '%Y-%m') as month,
country,
count(*) as trans_count,
sum(
if(state = 'approved', 1, 0)
) as approved_count,
sum(amount) as trans_total_amount,
sum(
if(state = 'approved', amount, 0)
) as approved_total_amount
from
Transactions
group by
date_format(trans_date, '%Y-%m'),
country;```Code language: SQL (Structured Query Language) (sql)```
Scroll to Top