1193.sql (328B)
1 SELECT LEFT(trans_date, 7) AS month, 2 country, 3 COUNT(*) AS trans_count, 4 SUM(state = 'approved') AS approved_count, 5 SUM(amount) AS trans_total_amount, 6 SUM(if(state = 'approved', amount, 0)) AS approved_total_amount 7 FROM Transactions 8 GROUP BY YEAR(trans_date), MONTH(trans_date), country