Problem: 1193. 每月交易 I
👨🏫 参考题解
Code
select DATE_FORMAT(trans_date, '%Y-%m') AS month,country,count(*) as trans_count,count(if(state = 'approved', 1, NULL)) as approved_count,sum(amount) as trans_total_amount,sum(if(state = 'approved', amount, 0)) as approved_total_amount
FROM Transactions
Group by month, country;