题目描述:
解题思路:
直接 行列转换 用case when 符合条件的 给 1 不符合条件的给0 然后sum聚合。
上代码:
/* Write your PL/SQL query statement below */
select substr(trans_date,1,7) month,
country ,
count(*) trans_count ,
sum(case when state = 'approved' then 1 else 0 end) approved_count ,
sum(amount) trans_total_amount,
sum(case when state = 'approved' then amount else 0 end ) approved_total_amount
from Transactions
group by substr(trans_date,1,7) ,country
order by substr(trans_date,1,7)