Untitled
# Write your MySQL query statement below SELECT DATE_FORMAT(T1.trans_date, '%Y-%m') AS transaction_month, T1.country, COUNT(*) AS trans_count, SUM(amount) AS total_amount, FROM Transactions AS T1 JOIN (SELECT DATE_FORMAT(trans_date, '%Y-%m') AS transaction_month,country, SUM(amount),COUNT(id) FROM Transactions WHERE state = 'approved' GROUP BY transaction_month,country) AS T2 ON T1.transaction_month = T2.transaction_month AND T1.country = T2.country GROUP BY T1.transaction_month,T1.country ORDER BY T1.transaction_month; SELECT DATE_FORMAT(trans_date, '%Y-%m') AS transaction_month,country, SUM(amount), COUNT(id) FROM Transactions WHERE state = 'approved' GROUP BY transaction_month,country
Leave a Comment