Reputation: 79
I need to query a single table that contains records for several different types of transactions:
and produce output in tabular format (without using an Excel pivot table, of course):
Is there a better way to do this than by JOINing several subqueries? And if there is no better way, how should I go about the order of the JOINs?
Upvotes: 0
Views: 108
Reputation: 1270623
Just use conditional aggregation:
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;
Upvotes: 1