高频 SQL 50 题(基础版)_1193. 每月交易 I
高频 SQL 50 题(基础版)_1193. 每月交易 I
# Write your MySQL query statement below
select
substr(trans_date,1,7) as month,
country,
count(*) as trans_count,
count(case when state='approved' THEN 1 END) as approved_count ,
sum(amount) as trans_total_amount ,
coalesce(sum(case when state='approved' THEN amount END),0) as approved_total_amount
from Transactions
group by month,country