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.
SELECT
문 작성COUNT
가 아닌 SUM
을 사용하는 것이 포인트였다.SELECT DATE_FORMAT(trans_date, '%Y-%m') as month, country,
COUNT(id) 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 1, 2