leetcode 1193 每月交易 I

Carl_ZhangJH / 2023-05-16 / 原文

leetcode 1193 每月交易 I

select t2.month, t1.country, count(t1.country) as trans_count, 
sum(t1.state = 'approved') as approved_count,
sum(t1.amount) as trans_total_amount,
sum(if(t1.state = 'approved', t1.amount, 0))as approved_total_amount 
from Transactions t1 
inner join (
    select id, date_format(trans_date,'%Y-%m') as month from Transactions
) t2
on t1.id = t2.id
group by t2.month,t1.country 

==