leetcode 1193 每月交易 I

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 

==

posted @ 2023-05-16 14:42  Carl_ZhangJH  阅读(15)  评论(0)    收藏  举报