17,082
社区成员
发帖
与我相关
我的任务
分享
create or replace procedure p_test
is
begin
execute immediate 'create table invest_analysis_tmp1 as
select a.cfg_id,
a.group_id,
sum(a.market_amt /
(select b.fund_amt
from evaluate_sum b
where b.eval_date = i_EvalDate
and b.group_id = a.group_id) * 100) s_market
from invest_analysis_record_tmp a
where a.eval_date =i_EvalDate
group by a.cfg_id, a.group_id
union
select a.cfg_id,"合计" group_id ,
sum(a.market_amt /
(select sum(b.fund_amt)
from evaluate_sum b
where b.eval_date = i_EvalDate
) * 100) s_market
from invest_analysis_record_tmp a
where a.eval_date = i_EvalDate
group by a.cfg_id';
execute immediate 'create table invest_analysis_tmp2 as
select * from invest_analysis_tmp1
union
select c.parent_id cfg_id,o.group_id, sum(to_number(o.s_market)) s_maket
from invest_analysis_tmp1 o, cfg_asset_category c
where o.cfg_id = c.id(+)
group by c.parent_id, o.group_id
union
select 9999 cfg_id, o.group_id, sum(to_number(o.s_market)) s_maket
from invest_analysis_tmp1 o, cfg_asset_category c
where o.cfg_id = c.id(+) and c.parent_id is not null
group by o.group_id';
execute immediate 'create table invest_analysis_tmp3 as
select * from
(select o.cfg_id id ,decode(o.cfg_id,9999,9999,c.parent_id) parent_id,
case when c.parent_id=1000 then c.cate_name||"小计"
when c.parent_id is null then "总计"
else c.cate_name end cate_name,
o.*
from invest_analysis_tmp2 o, cfg_asset_category c
where o.cfg_id=c.id(+))
pivot(sum(to_char(s_market,"FM99990.999")) for group_id in("1003",
"1004",
"1021",
"1022",
"1023",
"1024",
"1025",
"1026",
"1161",
"1162",
"合计"))';
end;