sql - SQL:需要查询具有多种交易类型的单列并以表格格式输出
解决方案
只需使用条件聚合:
select yyyymm,
sum(case when type = 'CNFF Iny' then amount end) as cnff_iny,
sum(case when type = 'CNFF Ret' then amount end) as cnff_ret,
. . . -- and so on for all the values
from t
group by yyyymm
order by yyyymm;