SQL过程按渠道统计重点业务发展情况

提取相关渠道数据,然后分别从相关业务表提取业务发展明细数据,分别计算每日业务进展

—放号 活跃率 存量 活跃率 宽带新增 活跃率 生态 活跃率 5G终端 活跃率

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_ta’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||’_shqd_ta as
select nvl(substr(a.orgid,8,1),’‘0’’) qx,b.name,a.orgid,a.orgname,a.unit_id,a.unit_name,
a.微网格编码,a.微网格名称,a.单位类型,a.渠道类型,a.渠道类别,
nvl(a.是否核心渠道,’‘0’’) 是否核心渠道,a.渠道经理工号,a.渠道经理
from zhyw.xxx_organization a,
zhyw.rpt_county b
where nvl(a.是否自办渠道,’‘0’’)=’‘社会渠道’’
and nvl(substr(a.orgid,8,1),’‘0’’)=b.county_id(+) ’ ;
execute immediate (SQL_STRING);

----放号

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_ta_fh’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_ta_fh as
select a.registerorgid,a.servnumber,a.subsid,a.prodid,a.prodname,a.createdate,
to_char(a.createdate,’‘yyyymm’’) cycle, to_char(a.createdate,’‘dd’’) create_dd
from zhyw.xxx_fanghao
’||v_monsr||’ a,
XXXX.sybb_’||v_monsr||’_shqd_ta b
where a.registerorgid=b.orgid
and to_char(a.createdate,’‘yyyymm’’)=’’’||v_monsr||’’’
and a.createdate-1<to_date(’’’||P_DAY||’’’,’‘yyyymmdd’’) ’ ;
execute immediate (SQL_STRING);

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_ta_fha’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_ta_fha as
select b.orgid sl_orgid,a.*
from XXXX.sybb
’||v_monsr||‘shqd_ta b ,
XXXX.sybb
’||v_monsr||’_shqd_ta_fh a
where b.orgid=a.registerorgid(+) ’ ;
execute immediate (SQL_STRING);

–宽带

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_ta_kd’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_ta_kd as
select a.recorgid,a.servnumber,a.subsid,
nvl(a.prodid_priv,a.prodid_rh) prodid,
nvl(a.privname_priv,a.privname_rh) privname,a.recdate,
to_char(a.recdate,’‘yyyymm’’) cycle, to_char(a.recdate,’‘dd’’) create_dd
from zhyw.zhai_yxkd_priv_subs a,
XXXX.sybb
’||v_monsr||’_shqd_ta b
where a.recorgid=b.orgid
and a.startdate<nvl(a.enddate,sysdate+9999)
and to_char(a.recdate,’‘yyyymm’’)=’’’||v_monsr||’’’
and a.recdate-1<to_date(’’’||P_DAY||’’’,’‘yyyymmdd’’) ’ ;
execute immediate (SQL_STRING);

–存量

    fan_drop_retable(upper('sybb_'||v_monsr||'_shqd_ta_cl'),'XXXX');
    SQL_STRING:='create table XXXX.sybb_'||v_monsr||'_shqd_ta_cl as

select distinct a.PROD_TYPE, a.orgid ,a.ORGNAME, a.unit_name,nvl(a.QX,’‘电子渠道’’)QX,a.subsid,a.oid,
qx_name,a.是否自办渠道,a.渠道类型 ,a.是否核心渠道, t6. 微网格编码, t6.微网格名称,a.班组类型 ,a.班组名称,a.SERVNUMBER,
a.recdate recdate , a.附加信息,
a.prodname,a.privname,a.recopid,zhyw.shc_del_tszf(a.notes)notes ,受理方式,鉴权,业务类型,
to_char(a.createdate,’‘yyyymmdd’’) createdate,a.startdate,a.enddate,a.qx_gs,a.渠道经理工号,a.渠道经理, 根据备注获取工号,
t3. 集团编号,t3.集团名称,t3.集团类型,t3.客户经理 ,个性化,备用字段1,备用字段2,备用字段3,a.status,
to_char(a.statusdate,’‘yyyymmdd’’) statusdate,to_char(a.mtd_flow) mtd_flow,
to_char(mtd_flow_次月) mtd_flow_次月,to_char(mtd_flow_次次月) mtd_flow_次次月,to_char(mtd_flow_次次次月) mtd_flow_次次次月, t4.kehu_type ,
case when t5.servnumber is not null then ‘‘1’’ end 是否员工号码,main_prodname
from zhyw.report_mx_month_’||v_monsr||‘new a,
zhyw.qcy_busscustsubs
’||v_monsr||’ t3,
( select * from zhyw.shc_ldjs_kehu_type ) t4,
( select servnumber from zhyw.zb_staff where status=’‘1’’ union
select distinct servnumber from zhyw.shc_tsyh where privname = ‘‘公免用户优惠’’ and enddate is null ) t5,
zhyw.shc_organization t6
where a.prod_type in ( select keywords from zhyw.shc_shishi_report_keywords where 是否聚合明细=’‘1’’ )
and to_char(a.recdate,’‘yyyymm’’)=’’’||v_monsr||’’’
and a.recdate-1<to_date(’’’||P_DAY||’’’,’‘yyyymmdd’’)
and a.servnumber=t3.servnumber(+)
and a.servnumber=t5.servnumber(+)
and a.subsid=t4.subsid(+)
and a.orgid=t6.orgid(+) ’ ;
execute immediate (SQL_STRING);

---特别说明: 需要剔除第一列“新模组升级”的号码中在后面“个性化”字段中的NULL,只保留计入模组升级)

fan_drop_retable(upper('sybb_'||v_monsr||'_shqd_ta_cla'),'XXXX');
    SQL_STRING:='create table XXXX.sybb_'||v_monsr||'_shqd_ta_cla as
select a.orgid registerorgid,a.servnumber,a.subsid,to_char(a.oid) prodid,a.prod_type prodname,a.recdate createdate,
to_char(a.recdate,''yyyymm'') cycle, to_char(a.recdate,''dd'') create_dd 
from  XXXX.sybb_'||v_monsr||'_shqd_ta_cl a,
XXXX.sybb_'||v_monsr||'_shqd_ta b
where a.orgid=b.orgid
and a.prod_type<>''新模组升级''
union all
select a.orgid registerorgid,a.servnumber,a.subsid,to_char(a.oid) prodid,a.prod_type prodname,a.recdate createdate,
to_char(a.recdate,''yyyymm'') cycle, to_char(a.recdate,''dd'') create_dd 
from  XXXX.sybb_'||v_monsr||'_shqd_ta_cl a,
XXXX.sybb_'||v_monsr||'_shqd_ta b
where a.orgid=b.orgid
and a.prod_type=''新模组升级'' and 个性化 is not null  ' ;
    execute immediate (SQL_STRING);

–生态 活跃率

–生态新增
fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_ta_st’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_ta_st as
select a.subsid,a.servnumber,a.item,a.recdate,a.recorgid,a.applyoperid,a.startdate,a.enddate,a.applyoid,
to_char(a.recdate,’‘yyyymm’’) cycle, to_char(a.recdate,’‘dd’’) create_dd
from zhyw.qcy_js_shengtai_subs a,
XXXX.sybb
’||v_monsr||’_shqd_ta b
where a.recorgid=b.orgid
and to_char(a.recdate,’‘yyyymm’’)=’’’||v_monsr||’’’
and a.recdate-1<to_date(’’’||P_DAY||’’’,’‘yyyymmdd’’) ’ ;
execute immediate (SQL_STRING);

--5G终端  活跃率
fan_drop_retable(upper('sybb_'||v_monsr||'_shqd_ta_zdxs'),'XXXX');
    SQL_STRING:='create table XXXX.sybb_'||v_monsr||'_shqd_ta_zdxs as
select a.* from XXXX.scjk_zdxs_slb_hz a,
 XXXX.sybb_'||v_monsr||'_shqd_ta b
where a.recorgid=b.orgid
and to_char(a.recdate,''yyyymm'')='''||v_monsr||''' 
and a.recdate-1<to_date('''||P_DAY||''',''yyyymmdd'')  ' ;
    execute immediate (SQL_STRING);


fan_drop_retable(upper('sybb_'||v_monsr||'_shqd_ta_zdxsa'),'XXXX');
    SQL_STRING:='create table XXXX.sybb_'||v_monsr||'_shqd_ta_zdxsa as
select a.*,b.term_brand,b.term_code,b.term_4g,nvl(b.term_5g,''0'')  term_5g
from XXXX.sybb_'||v_monsr||'_shqd_ta_zdxs a ,
ZIBO.DW_IMEI_TERMINFO_NEW_MS b
where substr(a.imei,1,8)=b.tac(+) ' ;
    execute immediate (SQL_STRING);

fan_drop_retable(upper('sybb_'||v_monsr||'_shqd_ta_zdxsb'),'XXXX');
    SQL_STRING:='create table XXXX.sybb_'||v_monsr||'_shqd_ta_zdxsb as
select a.*,to_char(a.recdate,''yyyymm'') cycle, to_char(a.recdate,''dd'') create_dd 
from XXXX.sybb_'||v_monsr||'_shqd_ta_zdxsa a 
where a.term_5g=''1''  ' ;
    execute immediate (SQL_STRING);

--------汇总

—放号
fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_ta_fhz’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_ta_fhz as
select ‘’’||P_DAY||’’’ 日期,a.registerorgid,
count() 总量,round(count()/to_number(substr( ‘’’||P_DAY||’’’,7,2)),2) 日均,
count(case when a.create_dd=’‘01’’ then a.subsid end) y01,
count(case when a.create_dd=’‘02’’ then a.subsid end) y02,
count(case when a.create_dd=’‘03’’ then a.subsid end) y03,
count(case when a.create_dd=’‘04’’ then a.subsid end) y04,
count(case when a.create_dd=’‘05’’ then a.subsid end) y05,
count(case when a.create_dd=’‘06’’ then a.subsid end) y06,
count(case when a.create_dd=’‘07’’ then a.subsid end) y07,
count(case when a.create_dd=’‘08’’ then a.subsid end) y08,
count(case when a.create_dd=’‘09’’ then a.subsid end) y09,
count(case when a.create_dd=’‘10’’ then a.subsid end) y10,
count(case when a.create_dd=’‘11’’ then a.subsid end) y11,
count(case when a.create_dd=’‘12’’ then a.subsid end) y12,
count(case when a.create_dd=’‘13’’ then a.subsid end) y13,
count(case when a.create_dd=’‘14’’ then a.subsid end) y14,
count(case when a.create_dd=’‘15’’ then a.subsid end) y15,
count(case when a.create_dd=’‘16’’ then a.subsid end) y16,
count(case when a.create_dd=’‘17’’ then a.subsid end) y17,
count(case when a.create_dd=’‘18’’ then a.subsid end) y18,
count(case when a.create_dd=’‘19’’ then a.subsid end) y19,
count(case when a.create_dd=’‘20’’ then a.subsid end) y20,
count(case when a.create_dd=’‘21’’ then a.subsid end) y21,
count(case when a.create_dd=’‘22’’ then a.subsid end) y22,
count(case when a.create_dd=’‘23’’ then a.subsid end) y23,
count(case when a.create_dd=’‘24’’ then a.subsid end) y24,
count(case when a.create_dd=’‘25’’ then a.subsid end) y25,
count(case when a.create_dd=’‘26’’ then a.subsid end) y26,
count(case when a.create_dd=’‘27’’ then a.subsid end) y27,
count(case when a.create_dd=’‘28’’ then a.subsid end) y28,
count(case when a.create_dd=’‘29’’ then a.subsid end) y29,
count(case when a.create_dd=’‘30’’ then a.subsid end) y30,
count(case when a.create_dd=’‘31’’ then a.subsid end) y31,
count(distinct a.create_dd) 发展日,
to_number(substr( ‘’’||P_DAY||’’’,7,2))-count(distinct a.create_dd) 未破零天数
from XXXX.sybb
’||v_monsr||’_shqd_ta_fha a
group by a.registerorgid ’ ;
execute immediate (SQL_STRING);

—存量

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_ta_clz’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_ta_clz as
select ‘’’||P_DAY||’’’ 日期,a.registerorgid,
count() 总量,round(count()/to_number(substr( ‘’’||P_DAY||’’’,7,2)),2) 日均,
count(case when a.create_dd=’‘01’’ then a.subsid end) y01,
count(case when a.create_dd=’‘02’’ then a.subsid end) y02,
count(case when a.create_dd=’‘03’’ then a.subsid end) y03,
count(case when a.create_dd=’‘04’’ then a.subsid end) y04,
count(case when a.create_dd=’‘05’’ then a.subsid end) y05,
count(case when a.create_dd=’‘06’’ then a.subsid end) y06,
count(case when a.create_dd=’‘07’’ then a.subsid end) y07,
count(case when a.create_dd=’‘08’’ then a.subsid end) y08,
count(case when a.create_dd=’‘09’’ then a.subsid end) y09,
count(case when a.create_dd=’‘10’’ then a.subsid end) y10,
count(case when a.create_dd=’‘11’’ then a.subsid end) y11,
count(case when a.create_dd=’‘12’’ then a.subsid end) y12,
count(case when a.create_dd=’‘13’’ then a.subsid end) y13,
count(case when a.create_dd=’‘14’’ then a.subsid end) y14,
count(case when a.create_dd=’‘15’’ then a.subsid end) y15,
count(case when a.create_dd=’‘16’’ then a.subsid end) y16,
count(case when a.create_dd=’‘17’’ then a.subsid end) y17,
count(case when a.create_dd=’‘18’’ then a.subsid end) y18,
count(case when a.create_dd=’‘19’’ then a.subsid end) y19,
count(case when a.create_dd=’‘20’’ then a.subsid end) y20,
count(case when a.create_dd=’‘21’’ then a.subsid end) y21,
count(case when a.create_dd=’‘22’’ then a.subsid end) y22,
count(case when a.create_dd=’‘23’’ then a.subsid end) y23,
count(case when a.create_dd=’‘24’’ then a.subsid end) y24,
count(case when a.create_dd=’‘25’’ then a.subsid end) y25,
count(case when a.create_dd=’‘26’’ then a.subsid end) y26,
count(case when a.create_dd=’‘27’’ then a.subsid end) y27,
count(case when a.create_dd=’‘28’’ then a.subsid end) y28,
count(case when a.create_dd=’‘29’’ then a.subsid end) y29,
count(case when a.create_dd=’‘30’’ then a.subsid end) y30,
count(case when a.create_dd=’‘31’’ then a.subsid end) y31,
count(distinct a.create_dd) 发展日,
to_number(substr( ‘’’||P_DAY||’’’,7,2))-count(distinct a.create_dd) 未破零天数
from XXXX.sybb
’||v_monsr||’_shqd_ta_cla a
group by a.registerorgid ’ ;
execute immediate (SQL_STRING);

–宽带

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_ta_kdz’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_ta_kdz as
select ‘’’||P_DAY||’’’ 日期,a.recorgid registerorgid,
count() 总量,round(count()/to_number(substr( ‘’’||P_DAY||’’’,7,2)),2) 日均,
count(case when a.create_dd=’‘01’’ then a.subsid end) y01,
count(case when a.create_dd=’‘02’’ then a.subsid end) y02,
count(case when a.create_dd=’‘03’’ then a.subsid end) y03,
count(case when a.create_dd=’‘04’’ then a.subsid end) y04,
count(case when a.create_dd=’‘05’’ then a.subsid end) y05,
count(case when a.create_dd=’‘06’’ then a.subsid end) y06,
count(case when a.create_dd=’‘07’’ then a.subsid end) y07,
count(case when a.create_dd=’‘08’’ then a.subsid end) y08,
count(case when a.create_dd=’‘09’’ then a.subsid end) y09,
count(case when a.create_dd=’‘10’’ then a.subsid end) y10,
count(case when a.create_dd=’‘11’’ then a.subsid end) y11,
count(case when a.create_dd=’‘12’’ then a.subsid end) y12,
count(case when a.create_dd=’‘13’’ then a.subsid end) y13,
count(case when a.create_dd=’‘14’’ then a.subsid end) y14,
count(case when a.create_dd=’‘15’’ then a.subsid end) y15,
count(case when a.create_dd=’‘16’’ then a.subsid end) y16,
count(case when a.create_dd=’‘17’’ then a.subsid end) y17,
count(case when a.create_dd=’‘18’’ then a.subsid end) y18,
count(case when a.create_dd=’‘19’’ then a.subsid end) y19,
count(case when a.create_dd=’‘20’’ then a.subsid end) y20,
count(case when a.create_dd=’‘21’’ then a.subsid end) y21,
count(case when a.create_dd=’‘22’’ then a.subsid end) y22,
count(case when a.create_dd=’‘23’’ then a.subsid end) y23,
count(case when a.create_dd=’‘24’’ then a.subsid end) y24,
count(case when a.create_dd=’‘25’’ then a.subsid end) y25,
count(case when a.create_dd=’‘26’’ then a.subsid end) y26,
count(case when a.create_dd=’‘27’’ then a.subsid end) y27,
count(case when a.create_dd=’‘28’’ then a.subsid end) y28,
count(case when a.create_dd=’‘29’’ then a.subsid end) y29,
count(case when a.create_dd=’‘30’’ then a.subsid end) y30,
count(case when a.create_dd=’‘31’’ then a.subsid end) y31,
count(distinct a.create_dd) 发展日,
to_number(substr( ‘’’||P_DAY||’’’,7,2))-count(distinct a.create_dd) 未破零天数
from XXXX.sybb
’||v_monsr||’_shqd_ta_kd a
group by a.recorgid ’ ;
execute immediate (SQL_STRING);

—生态

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_ta_stz’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_ta_stz as
select ‘’’||P_DAY||’’’ 日期,a.recorgid registerorgid,
count() 总量,round(count()/to_number(substr( ‘’’||P_DAY||’’’,7,2)),2) 日均,
count(case when a.create_dd=’‘01’’ then a.subsid end) y01,
count(case when a.create_dd=’‘02’’ then a.subsid end) y02,
count(case when a.create_dd=’‘03’’ then a.subsid end) y03,
count(case when a.create_dd=’‘04’’ then a.subsid end) y04,
count(case when a.create_dd=’‘05’’ then a.subsid end) y05,
count(case when a.create_dd=’‘06’’ then a.subsid end) y06,
count(case when a.create_dd=’‘07’’ then a.subsid end) y07,
count(case when a.create_dd=’‘08’’ then a.subsid end) y08,
count(case when a.create_dd=’‘09’’ then a.subsid end) y09,
count(case when a.create_dd=’‘10’’ then a.subsid end) y10,
count(case when a.create_dd=’‘11’’ then a.subsid end) y11,
count(case when a.create_dd=’‘12’’ then a.subsid end) y12,
count(case when a.create_dd=’‘13’’ then a.subsid end) y13,
count(case when a.create_dd=’‘14’’ then a.subsid end) y14,
count(case when a.create_dd=’‘15’’ then a.subsid end) y15,
count(case when a.create_dd=’‘16’’ then a.subsid end) y16,
count(case when a.create_dd=’‘17’’ then a.subsid end) y17,
count(case when a.create_dd=’‘18’’ then a.subsid end) y18,
count(case when a.create_dd=’‘19’’ then a.subsid end) y19,
count(case when a.create_dd=’‘20’’ then a.subsid end) y20,
count(case when a.create_dd=’‘21’’ then a.subsid end) y21,
count(case when a.create_dd=’‘22’’ then a.subsid end) y22,
count(case when a.create_dd=’‘23’’ then a.subsid end) y23,
count(case when a.create_dd=’‘24’’ then a.subsid end) y24,
count(case when a.create_dd=’‘25’’ then a.subsid end) y25,
count(case when a.create_dd=’‘26’’ then a.subsid end) y26,
count(case when a.create_dd=’‘27’’ then a.subsid end) y27,
count(case when a.create_dd=’‘28’’ then a.subsid end) y28,
count(case when a.create_dd=’‘29’’ then a.subsid end) y29,
count(case when a.create_dd=’‘30’’ then a.subsid end) y30,
count(case when a.create_dd=’‘31’’ then a.subsid end) y31,
count(distinct a.create_dd) 发展日,
to_number(substr( ‘’’||P_DAY||’’’,7,2))-count(distinct a.create_dd) 未破零天数
from XXXX.sybb
’||v_monsr||’_shqd_ta_st a
group by a.recorgid ’ ;
execute immediate (SQL_STRING);

-----5G终端

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_ta_zdxsz’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_ta_zdxsz as
select ‘’’||P_DAY||’’’ 日期,a.recorgid registerorgid,
count() 总量,round(count()/to_number(substr( ‘’’||P_DAY||’’’,7,2)),2) 日均,
count(case when a.create_dd=’‘01’’ then a.imei end) y01,
count(case when a.create_dd=’‘02’’ then a.imei end) y02,
count(case when a.create_dd=’‘03’’ then a.imei end) y03,
count(case when a.create_dd=’‘04’’ then a.imei end) y04,
count(case when a.create_dd=’‘05’’ then a.imei end) y05,
count(case when a.create_dd=’‘06’’ then a.imei end) y06,
count(case when a.create_dd=’‘07’’ then a.imei end) y07,
count(case when a.create_dd=’‘08’’ then a.imei end) y08,
count(case when a.create_dd=’‘09’’ then a.imei end) y09,
count(case when a.create_dd=’‘10’’ then a.imei end) y10,
count(case when a.create_dd=’‘11’’ then a.imei end) y11,
count(case when a.create_dd=’‘12’’ then a.imei end) y12,
count(case when a.create_dd=’‘13’’ then a.imei end) y13,
count(case when a.create_dd=’‘14’’ then a.imei end) y14,
count(case when a.create_dd=’‘15’’ then a.imei end) y15,
count(case when a.create_dd=’‘16’’ then a.imei end) y16,
count(case when a.create_dd=’‘17’’ then a.imei end) y17,
count(case when a.create_dd=’‘18’’ then a.imei end) y18,
count(case when a.create_dd=’‘19’’ then a.imei end) y19,
count(case when a.create_dd=’‘20’’ then a.imei end) y20,
count(case when a.create_dd=’‘21’’ then a.imei end) y21,
count(case when a.create_dd=’‘22’’ then a.imei end) y22,
count(case when a.create_dd=’‘23’’ then a.imei end) y23,
count(case when a.create_dd=’‘24’’ then a.imei end) y24,
count(case when a.create_dd=’‘25’’ then a.imei end) y25,
count(case when a.create_dd=’‘26’’ then a.imei end) y26,
count(case when a.create_dd=’‘27’’ then a.imei end) y27,
count(case when a.create_dd=’‘28’’ then a.imei end) y28,
count(case when a.create_dd=’‘29’’ then a.imei end) y29,
count(case when a.create_dd=’‘30’’ then a.imei end) y30,
count(case when a.create_dd=’‘31’’ then a.imei end) y31,
count(distinct a.create_dd) 发展日,
to_number(substr( ‘’’||P_DAY||’’’,7,2))-count(distinct a.create_dd) 未破零天数
from XXXX.sybb
’||v_monsr||’_shqd_ta_zdxsb a
group by a.recorgid ’ ;
execute immediate (SQL_STRING);

------五项合并

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_tsxz’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_tsxz as
select ‘’’||P_DAY||’’’ 日期,a.registerorgid registerorgid,
count() 总量,round(count()/to_number(substr( ‘’’||P_DAY||’’’,7,2)),2) 日均,
count(case when a.create_dd=’‘01’’ then a.subsid end) y01,
count(case when a.create_dd=’‘02’’ then a.subsid end) y02,
count(case when a.create_dd=’‘03’’ then a.subsid end) y03,
count(case when a.create_dd=’‘04’’ then a.subsid end) y04,
count(case when a.create_dd=’‘05’’ then a.subsid end) y05,
count(case when a.create_dd=’‘06’’ then a.subsid end) y06,
count(case when a.create_dd=’‘07’’ then a.subsid end) y07,
count(case when a.create_dd=’‘08’’ then a.subsid end) y08,
count(case when a.create_dd=’‘09’’ then a.subsid end) y09,
count(case when a.create_dd=’‘10’’ then a.subsid end) y10,
count(case when a.create_dd=’‘11’’ then a.subsid end) y11,
count(case when a.create_dd=’‘12’’ then a.subsid end) y12,
count(case when a.create_dd=’‘13’’ then a.subsid end) y13,
count(case when a.create_dd=’‘14’’ then a.subsid end) y14,
count(case when a.create_dd=’‘15’’ then a.subsid end) y15,
count(case when a.create_dd=’‘16’’ then a.subsid end) y16,
count(case when a.create_dd=’‘17’’ then a.subsid end) y17,
count(case when a.create_dd=’‘18’’ then a.subsid end) y18,
count(case when a.create_dd=’‘19’’ then a.subsid end) y19,
count(case when a.create_dd=’‘20’’ then a.subsid end) y20,
count(case when a.create_dd=’‘21’’ then a.subsid end) y21,
count(case when a.create_dd=’‘22’’ then a.subsid end) y22,
count(case when a.create_dd=’‘23’’ then a.subsid end) y23,
count(case when a.create_dd=’‘24’’ then a.subsid end) y24,
count(case when a.create_dd=’‘25’’ then a.subsid end) y25,
count(case when a.create_dd=’‘26’’ then a.subsid end) y26,
count(case when a.create_dd=’‘27’’ then a.subsid end) y27,
count(case when a.create_dd=’‘28’’ then a.subsid end) y28,
count(case when a.create_dd=’‘29’’ then a.subsid end) y29,
count(case when a.create_dd=’‘30’’ then a.subsid end) y30,
count(case when a.create_dd=’‘31’’ then a.subsid end) y31,
count(distinct a.create_dd) 发展日,
to_number(substr( ‘’’||P_DAY||’’’,7,2))-count(distinct a.create_dd) 未破零天数
from (select a.registerorgid,a.subsid,a.cycle,a.create_dd
from XXXX.sybb
’||v_monsr||‘shqd_ta_fha a
union all
select a.registerorgid,a.subsid,a.cycle,a.create_dd
from XXXX.sybb
’||v_monsr||‘shqd_ta_cla a
union all
select a.recorgid registerorgid,a.subsid,a.cycle,a.create_dd
from XXXX.sybb
’||v_monsr||‘shqd_ta_kd a
union all
select a.recorgid registerorgid,a.subsid,a.cycle,a.create_dd
from XXXX.sybb
’||v_monsr||‘shqd_ta_st a
union all
select a.recorgid registerorgid,a.entityid subsid,a.cycle,a.create_dd
from XXXX.sybb
’||v_monsr||’_shqd_ta_zdxsb a ) a
group by a.registerorgid ’ ;
execute immediate (SQL_STRING);

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_hzfh’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_hzfh as
select ‘’’||P_DAY||’’’ 日期,a.*,’‘放号’’ 类型,nvl(b.总量,0) 总量,nvl(b.日均,0) 日均,
nvl(b.y01,0) y01,nvl(b.Y02,’‘0’’) Y02 ,nvl(b.Y03,’‘0’’) Y03 ,nvl(b.Y04,’‘0’’) Y04 ,
nvl(b.Y05,’‘0’’) Y05 ,nvl(b.Y06,’‘0’’) Y06 ,nvl(b.Y07,’‘0’’) Y07 ,nvl(b.Y08,’‘0’’) Y08 ,
nvl(b.Y09,’‘0’’) Y09 ,nvl(b.Y10,’‘0’’) Y10 ,nvl(b.Y11,’‘0’’) Y11 ,nvl(b.Y12,’‘0’’) Y12 ,
nvl(b.Y13,’‘0’’) Y13 ,nvl(b.Y14,’‘0’’) Y14 ,nvl(b.Y15,’‘0’’) Y15 ,nvl(b.Y16,’‘0’’) Y16 ,
nvl(b.Y17,’‘0’’) Y17 ,nvl(b.Y18,’‘0’’) Y18 ,nvl(b.Y19,’‘0’’) Y19 ,nvl(b.Y20,’‘0’’) Y20 ,
nvl(b.Y21,’‘0’’) Y21 ,nvl(b.Y22,’‘0’’) Y22 ,nvl(b.Y23,’‘0’’) Y23 ,nvl(b.Y24,’‘0’’) Y24 ,
nvl(b.Y25,’‘0’’) Y25 ,nvl(b.Y26,’‘0’’) Y26 ,nvl(b.Y27,’‘0’’) Y27 ,nvl(b.Y28,’‘0’’) Y28 ,
nvl(b.Y29,’‘0’’) Y29 ,nvl(b.Y30,’‘0’’) Y30 ,nvl(b.Y31,’‘0’’) Y31 ,nvl(b.发展日,’‘0’’) 发展日 ,
nvl(b.未破零天数,to_number(substr( ‘’’||P_DAY||’’’,7,2))) 未破零天数
from
(select * from XXXX.sybb
’||v_monsr||‘shqd_ta a where a.name is not null ) a,
XXXX.sybb
’||v_monsr||’_shqd_ta_fhz b
where a.orgid=b.registerorgid(+) ’ ;
execute immediate (SQL_STRING);

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_hzcl’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_hzcl as
select ‘’’||P_DAY||’’’ 日期,a.*,’‘存量’’ 类型,nvl(b.总量,0) 总量,nvl(b.日均,0) 日均,
nvl(b.y01,0) y01,nvl(b.Y02,’‘0’’) Y02 ,nvl(b.Y03,’‘0’’) Y03 ,nvl(b.Y04,’‘0’’) Y04 ,
nvl(b.Y05,’‘0’’) Y05 ,nvl(b.Y06,’‘0’’) Y06 ,nvl(b.Y07,’‘0’’) Y07 ,nvl(b.Y08,’‘0’’) Y08 ,
nvl(b.Y09,’‘0’’) Y09 ,nvl(b.Y10,’‘0’’) Y10 ,nvl(b.Y11,’‘0’’) Y11 ,nvl(b.Y12,’‘0’’) Y12 ,
nvl(b.Y13,’‘0’’) Y13 ,nvl(b.Y14,’‘0’’) Y14 ,nvl(b.Y15,’‘0’’) Y15 ,nvl(b.Y16,’‘0’’) Y16 ,
nvl(b.Y17,’‘0’’) Y17 ,nvl(b.Y18,’‘0’’) Y18 ,nvl(b.Y19,’‘0’’) Y19 ,nvl(b.Y20,’‘0’’) Y20 ,
nvl(b.Y21,’‘0’’) Y21 ,nvl(b.Y22,’‘0’’) Y22 ,nvl(b.Y23,’‘0’’) Y23 ,nvl(b.Y24,’‘0’’) Y24 ,
nvl(b.Y25,’‘0’’) Y25 ,nvl(b.Y26,’‘0’’) Y26 ,nvl(b.Y27,’‘0’’) Y27 ,nvl(b.Y28,’‘0’’) Y28 ,
nvl(b.Y29,’‘0’’) Y29 ,nvl(b.Y30,’‘0’’) Y30 ,nvl(b.Y31,’‘0’’) Y31 ,nvl(b.发展日,’‘0’’) 发展日 ,
nvl(b.未破零天数,to_number(substr( ‘’’||P_DAY||’’’,7,2))) 未破零天数
from
(select * from XXXX.sybb
’||v_monsr||‘shqd_ta a where a.name is not null ) a,
XXXX.sybb
’||v_monsr||’_shqd_ta_clz b
where a.orgid=b.registerorgid(+) ’ ;
execute immediate (SQL_STRING);

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_hzkd’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_hzkd as
select ‘’’||P_DAY||’’’ 日期,a.*,’‘宽带’’ 类型,nvl(b.总量,0) 总量,nvl(b.日均,0) 日均,
nvl(b.y01,0) y01,nvl(b.Y02,’‘0’’) Y02 ,nvl(b.Y03,’‘0’’) Y03 ,nvl(b.Y04,’‘0’’) Y04 ,
nvl(b.Y05,’‘0’’) Y05 ,nvl(b.Y06,’‘0’’) Y06 ,nvl(b.Y07,’‘0’’) Y07 ,nvl(b.Y08,’‘0’’) Y08 ,
nvl(b.Y09,’‘0’’) Y09 ,nvl(b.Y10,’‘0’’) Y10 ,nvl(b.Y11,’‘0’’) Y11 ,nvl(b.Y12,’‘0’’) Y12 ,
nvl(b.Y13,’‘0’’) Y13 ,nvl(b.Y14,’‘0’’) Y14 ,nvl(b.Y15,’‘0’’) Y15 ,nvl(b.Y16,’‘0’’) Y16 ,
nvl(b.Y17,’‘0’’) Y17 ,nvl(b.Y18,’‘0’’) Y18 ,nvl(b.Y19,’‘0’’) Y19 ,nvl(b.Y20,’‘0’’) Y20 ,
nvl(b.Y21,’‘0’’) Y21 ,nvl(b.Y22,’‘0’’) Y22 ,nvl(b.Y23,’‘0’’) Y23 ,nvl(b.Y24,’‘0’’) Y24 ,
nvl(b.Y25,’‘0’’) Y25 ,nvl(b.Y26,’‘0’’) Y26 ,nvl(b.Y27,’‘0’’) Y27 ,nvl(b.Y28,’‘0’’) Y28 ,
nvl(b.Y29,’‘0’’) Y29 ,nvl(b.Y30,’‘0’’) Y30 ,nvl(b.Y31,’‘0’’) Y31 ,nvl(b.发展日,’‘0’’) 发展日 ,
nvl(b.未破零天数,to_number(substr( ‘’’||P_DAY||’’’,7,2))) 未破零天数
from
(select * from XXXX.sybb
’||v_monsr||‘shqd_ta a where a.name is not null ) a,
XXXX.sybb
’||v_monsr||’_shqd_ta_kdz b
where a.orgid=b.registerorgid(+) ’ ;
execute immediate (SQL_STRING);

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_hzst’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_hzst as
select ‘’’||P_DAY||’’’ 日期,a.*,’‘生态’’ 类型,nvl(b.总量,0) 总量,nvl(b.日均,0) 日均,
nvl(b.y01,0) y01,nvl(b.Y02,’‘0’’) Y02 ,nvl(b.Y03,’‘0’’) Y03 ,nvl(b.Y04,’‘0’’) Y04 ,
nvl(b.Y05,’‘0’’) Y05 ,nvl(b.Y06,’‘0’’) Y06 ,nvl(b.Y07,’‘0’’) Y07 ,nvl(b.Y08,’‘0’’) Y08 ,
nvl(b.Y09,’‘0’’) Y09 ,nvl(b.Y10,’‘0’’) Y10 ,nvl(b.Y11,’‘0’’) Y11 ,nvl(b.Y12,’‘0’’) Y12 ,
nvl(b.Y13,’‘0’’) Y13 ,nvl(b.Y14,’‘0’’) Y14 ,nvl(b.Y15,’‘0’’) Y15 ,nvl(b.Y16,’‘0’’) Y16 ,
nvl(b.Y17,’‘0’’) Y17 ,nvl(b.Y18,’‘0’’) Y18 ,nvl(b.Y19,’‘0’’) Y19 ,nvl(b.Y20,’‘0’’) Y20 ,
nvl(b.Y21,’‘0’’) Y21 ,nvl(b.Y22,’‘0’’) Y22 ,nvl(b.Y23,’‘0’’) Y23 ,nvl(b.Y24,’‘0’’) Y24 ,
nvl(b.Y25,’‘0’’) Y25 ,nvl(b.Y26,’‘0’’) Y26 ,nvl(b.Y27,’‘0’’) Y27 ,nvl(b.Y28,’‘0’’) Y28 ,
nvl(b.Y29,’‘0’’) Y29 ,nvl(b.Y30,’‘0’’) Y30 ,nvl(b.Y31,’‘0’’) Y31 ,nvl(b.发展日,’‘0’’) 发展日 ,
nvl(b.未破零天数,to_number(substr( ‘’’||P_DAY||’’’,7,2))) 未破零天数
from
(select * from XXXX.sybb
’||v_monsr||‘shqd_ta a where a.name is not null ) a,
XXXX.sybb
’||v_monsr||’_shqd_ta_stz b
where a.orgid=b.registerorgid(+) ’ ;
execute immediate (SQL_STRING);

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_hz5G’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_hz5G as
select ‘’’||P_DAY||’’’ 日期,a.*,’‘5G终端’’ 类型,nvl(b.总量,0) 总量,nvl(b.日均,0) 日均,
nvl(b.y01,0) y01,nvl(b.Y02,’‘0’’) Y02 ,nvl(b.Y03,’‘0’’) Y03 ,nvl(b.Y04,’‘0’’) Y04 ,
nvl(b.Y05,’‘0’’) Y05 ,nvl(b.Y06,’‘0’’) Y06 ,nvl(b.Y07,’‘0’’) Y07 ,nvl(b.Y08,’‘0’’) Y08 ,
nvl(b.Y09,’‘0’’) Y09 ,nvl(b.Y10,’‘0’’) Y10 ,nvl(b.Y11,’‘0’’) Y11 ,nvl(b.Y12,’‘0’’) Y12 ,
nvl(b.Y13,’‘0’’) Y13 ,nvl(b.Y14,’‘0’’) Y14 ,nvl(b.Y15,’‘0’’) Y15 ,nvl(b.Y16,’‘0’’) Y16 ,
nvl(b.Y17,’‘0’’) Y17 ,nvl(b.Y18,’‘0’’) Y18 ,nvl(b.Y19,’‘0’’) Y19 ,nvl(b.Y20,’‘0’’) Y20 ,
nvl(b.Y21,’‘0’’) Y21 ,nvl(b.Y22,’‘0’’) Y22 ,nvl(b.Y23,’‘0’’) Y23 ,nvl(b.Y24,’‘0’’) Y24 ,
nvl(b.Y25,’‘0’’) Y25 ,nvl(b.Y26,’‘0’’) Y26 ,nvl(b.Y27,’‘0’’) Y27 ,nvl(b.Y28,’‘0’’) Y28 ,
nvl(b.Y29,’‘0’’) Y29 ,nvl(b.Y30,’‘0’’) Y30 ,nvl(b.Y31,’‘0’’) Y31 ,nvl(b.发展日,’‘0’’) 发展日 ,
nvl(b.未破零天数,to_number(substr( ‘’’||P_DAY||’’’,7,2))) 未破零天数
from
(select * from XXXX.sybb
’||v_monsr||‘shqd_ta a where a.name is not null ) a,
XXXX.sybb
’||v_monsr||’_shqd_ta_zdxsz b
where a.orgid=b.registerorgid(+) ’ ;
execute immediate (SQL_STRING);

fan_drop_retable(upper(‘sybb_’||v_monsr||‘shqd_hzzo’),‘XXXX’);
SQL_STRING:='create table XXXX.sybb
’||v_monsr||‘shqd_hzzo as
select ‘’’||P_DAY||’’’ 日期,a.*,’‘合并’’ 类型,nvl(b.总量,0) 总量,nvl(b.日均,0) 日均,
nvl(b.y01,0) y01,nvl(b.Y02,’‘0’’) Y02 ,nvl(b.Y03,’‘0’’) Y03 ,nvl(b.Y04,’‘0’’) Y04 ,
nvl(b.Y05,’‘0’’) Y05 ,nvl(b.Y06,’‘0’’) Y06 ,nvl(b.Y07,’‘0’’) Y07 ,nvl(b.Y08,’‘0’’) Y08 ,
nvl(b.Y09,’‘0’’) Y09 ,nvl(b.Y10,’‘0’’) Y10 ,nvl(b.Y11,’‘0’’) Y11 ,nvl(b.Y12,’‘0’’) Y12 ,
nvl(b.Y13,’‘0’’) Y13 ,nvl(b.Y14,’‘0’’) Y14 ,nvl(b.Y15,’‘0’’) Y15 ,nvl(b.Y16,’‘0’’) Y16 ,
nvl(b.Y17,’‘0’’) Y17 ,nvl(b.Y18,’‘0’’) Y18 ,nvl(b.Y19,’‘0’’) Y19 ,nvl(b.Y20,’‘0’’) Y20 ,
nvl(b.Y21,’‘0’’) Y21 ,nvl(b.Y22,’‘0’’) Y22 ,nvl(b.Y23,’‘0’’) Y23 ,nvl(b.Y24,’‘0’’) Y24 ,
nvl(b.Y25,’‘0’’) Y25 ,nvl(b.Y26,’‘0’’) Y26 ,nvl(b.Y27,’‘0’’) Y27 ,nvl(b.Y28,’‘0’’) Y28 ,
nvl(b.Y29,’‘0’’) Y29 ,nvl(b.Y30,’‘0’’) Y30 ,nvl(b.Y31,’‘0’’) Y31 ,nvl(b.发展日,’‘0’’) 发展日 ,
nvl(b.未破零天数,to_number(substr( ‘’’||P_DAY||’’’,7,2))) 未破零天数
from
(select * from XXXX.sybb
’||v_monsr||‘shqd_ta a where a.name is not null ) a,
XXXX.sybb
’||v_monsr||’_shqd_tsxz b
where a.orgid=b.registerorgid(+) ’ ;
execute immediate (SQL_STRING);

SQL_STRING:=‘delete from XXXX.sybb_shqd_hzzo a where a.日期=’’’||P_DAY||’’’ ’ ;
execute immediate (SQL_STRING);
commit;

SQL_STRING:=‘insert into XXXX.sybb_shqd_hzzo
select * from XXXX.sybb_’||v_monsr||‘shqd_hzzo a
union all
select * from XXXX.sybb
’||v_monsr||‘shqd_hzfh a
union all
select * from XXXX.sybb
’||v_monsr||‘shqd_hzcl a
union all
select * from XXXX.sybb
’||v_monsr||‘shqd_hzkd a
union all
select * from XXXX.sybb
’||v_monsr||‘shqd_hzst a
union all
select * from XXXX.sybb
’||v_monsr||’_shqd_hz5G a ’ ;
execute immediate (SQL_STRING);
commit;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值