我有以下原始数据表:
所有者 | 策略 | POSITION_FLAG | 50001 | CompanyA | 股本 | 1 |
---|---|---|---|
50002 | CompanyA | 股本 | 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