Oracle / SQL -数据分组汇总表



我有以下原始数据表:

帐户tbody> <<tr>
所有者策略POSITION_FLAG
50001CompanyA股本1
50002CompanyA股本0
50002为CompanyB固定收益1

您可以使用条件聚合:

select owner,
sum(case when strategy = 'Equity' and position_flag = 1 then 1 else 0 end)
|| '/' 
|| sum(case when strategy = 'Equity' then 1 else 0 end) equity,
sum(case when strategy = 'Fixed Income' and position_flag = 1 then 1 else 0 end)
|| '/' 
|| sum(case when strategy = 'Fixed Income' then 1 else 0 end) fixed_income
from mytable
group by owner

最新更新