20231012_数据库过程_渠道评估体系数据

----20230801 渠道评估体系数据

------微企经理直销渠道对应关系 
---工号  微企经理归属  直销渠道  类型
---  create table zhyw.xc_qdpgtx_wqjl_zxqd_bdcd
---(operid varchar2(18),opername varchar2(80),zxqd_id varchar2(80),zxqd_name varchar2(80),type varchar2(80),in_time date);

--- select * from zhyw.xc_qdpgtx_wqjl_zxqd_bdcd for update ;
 
--- update zhyw.xc_qdpgtx_wqjl_zxqd_bdcd a set a.in_time=sysdate
--- where a.in_time is null;

---直销员与微企经理

zhyw.shc_drop_retable(upper('xc_qdpgtx_wqjl_jfzxy_sjxf'),'ZHYW');
SQL_STRING:='create table zhyw.xc_qdpgtx_wqjl_jfzxy_sjxf as
select TO_CHAR(OP_TIME,''YYYYMMDD'') 日期,
ID   主键  ,
APP_ID   应用编码  ,
APP_CODE   平台编码  ,
APP_NAME   平台名称  ,
PARTNER_NAME   合伙人姓名  ,
PARTNER_MOBILE   合伙人手机号  ,
PARTNER_AUDIT_STATUS   合伙人审核状态  ,
PARTNER_TYPE   合伙人类型  ,
PARTNER_ROLE   合伙人角色  ,
PARTNER_ID   合伙人身份证号  ,
PARTNER_ADDRESS   合伙人地址  ,
PARTNER_AUTH_STATUS   合伙人认证状态  ,
PARTNER_RESOURCE   合伙人来源  ,
PARTNER_DEVELOP_STATUS   合伙人是否可以发展下线  ,
REC_PARTNER_MOBILE   合伙人推荐手机号  ,
REC_PARTNER_NAME   合伙人推荐姓名  ,
PARTNER_STATUS   合伙人状态  ,
PARTNER_SHOP_CODE   合伙店团队编码  ,
PARTNER_SHOP_NAME   合伙店团队名称  ,
PARTNER_SHOP_IMAGE   合伙店团队图片  ,
PARTNER_SHOP_STATUS   合伙店团队状态  ,
EMPLOYEE_NUMBER   BOSS工号  ,
EMPLOYEE_MOBILE   BOSS手机号  ,
EMPLOYEE_NAME   BOSS姓名  ,
PROVINCE_CODE   省份编码  ,
CITY_CODE   城市编码  ,
DISTRICT_CODE   地区编码  ,
PROVINCE   省份  ,
CITY   城市  ,
DISTRICT   地区  ,
CREATED_BY   创建人  ,
CREATED_TIME   创建时间  ,
UPDATED_BY   更新人  ,
UPDATED_TIME   更新时间  ,
DELETED   是否删除1可用2删除  ,
PHY_STORE_NAME   实体店名称  ,
PHY_STORE_STATUS   是否有实体店1有2没有  ,
PHY_STORE_REGISTRATION_NUMBER   实体店营业执照注册号  ,
PHY_STORE_LONGITUDE   实体店经度  ,
PHY_STORE_LATITUDE   实体店纬度  ,
PHY_STORE_LOCATION   实体店位置地图获取  ,
PHY_STORE_DISTRICT   实体店区域地图获取  ,
PHY_STORE_ADDRESS   实体店详细地址  ,
PHY_STORE_CONTACTS   实体店联系人  ,
PHY_STORE_CONTACTS_NUM   实体店联系电话  ,
PHY_STORE_LICENSE   实体店营业执照  ,
PHY_STORE_IMAGE   实体店照片  ,
SHOPPER_ORG_ID   工号对应店长用户信息所属机构id  ,
SELF_EMPLOYEE_NUMBER   自营工号  ,
FOUR_ORG_CODE   四级机构编码  ,
FOUR_ORG_NAME   四级机构名称  ,
FIVE_ORG_CODE   五级机构编码  ,
FIVE_ORG_NAME   五级机构名称  ,
STATUS_UPDATED_TIME   状态更新时间  ,
FIRST_INDUSTRY_CODE   行业形态编码一级编码  ,
FIRST_INDUSTRY_NAME   行业形态名称一级名称  ,
SECOND_INDUSTRY_CODE   行业形态属性编码二级编码  ,
SECOND_INDUSTRY_NAME   行业形态属性名称二级名称  
from zibo.ods_partner_info_ds
 where  city  like ''淄博%''  
 and partner_role in (84,85)    ';
EXECUTE IMMEDIATE (SQL_STRING);


zhyw.shc_drop_retable(upper('xc_qdpgtx_wqjl_jfzxy_sjxfa'),'ZHYW');
SQL_STRING:='create table zhyw.xc_qdpgtx_wqjl_jfzxy_sjxfa as
select a.* from 
(select a.*,row_number() over (partition by a.合伙人手机号  order by a.创建时间 desc ) 排名 
 from zhyw.xc_qdpgtx_wqjl_jfzxy_sjxf a
 where to_date(a.创建时间,''yyyy-mm-dd hh24:mi:ss'')-1 < to_date('''||P_DAY||''',''yyyymmdd'') ) a
 where a.排名 = 1 ';
EXECUTE IMMEDIATE (SQL_STRING);
 
 zhyw.shc_drop_retable(upper('xc_qdpgtx_wqjl_jfzxy_sjxfb'),'ZHYW');
SQL_STRING:='create table zhyw.xc_qdpgtx_wqjl_jfzxy_sjxfb as
 select a.合伙人姓名,a.合伙人手机号,a.合伙人角色,a.合伙人审核状态,a.合伙人认证状态,a.合伙人状态,a.boss工号,a.boss手机号,a.boss姓名,b.orgid,c.orgname
 from zhyw.xc_qdpgtx_wqjl_jfzxy_sjxfa a,
 tbcs.operator@bcv b,
 tbcs.organization@bcv c
 where a.boss工号=b.operid(+)
 and b.orgid=c.orgid(+) ';
EXECUTE IMMEDIATE (SQL_STRING);
 

 
   zhyw.shc_drop_retable(upper('xc_qdpgtx_wqjl_jfzxy_sjxfc'),'ZHYW');
SQL_STRING:='create table zhyw.xc_qdpgtx_wqjl_jfzxy_sjxfc as
  select a.*,b.status,b.渠道类别,nvl(case when nvl(b.是否核心渠道,''0'')=''1'' then ''是'' end,''否'') 是否核心渠道
  from zhyw.xc_qdpgtx_wqjl_jfzxy_sjxfb a,
  zhyw.shc_organization_'||v_monsr||' b
  where a.orgid=b.orgid(+) ';
EXECUTE IMMEDIATE (SQL_STRING);
  
  

 
 ---微企经理直销员

zhyw.shc_drop_retable(upper('xc_qdpgtx_wqjl_zxqd_zxsj'),'ZHYW');
SQL_STRING:='create table zhyw.xc_qdpgtx_wqjl_zxqd_zxsj as
select * from 
(select b.county_id,b.jf_county_id,b.note,b.name,a.*,c.合伙人手机号,c.合伙人姓名,c.合伙人状态,
row_number() over (partition by a.zxqd_id,c.合伙人手机号  order by a.in_time desc ) 排名 
from zhyw.xc_qdpgtx_wqjl_zxqd_bdcd a,
(select * from zhyw.rpt_county b where b.county_id<>''0'') b,
zhyw.xc_qdpgtx_wqjl_jfzxy_sjxfc c
where substr(a.operid,2,1)=b.county_id(+)
and a.zxqd_id=c.orgid(+)
and a.OPERID<>''#N/A''
and a.TYPE=''微企经理直销渠道'') a
where a.in_time in (select max(a.in_time) from  zhyw.xc_qdpgtx_wqjl_zxqd_bdcd a 
where a.TYPE=''微企经理直销渠道'' )
and a.合伙人状态=''1'' ';
EXECUTE IMMEDIATE (SQL_STRING);

-------------20230824 校园渠道与统管渠道

--create table zhyw.xc_qdpgtx_xiaoyuan_tongguan
--(orgid varchar2(50),type varchar2(18));

--select * from zhyw.xc_qdpgtx_xiaoyuan_tongguan for update ;

----渠道经理对应渠道关系
zhyw.shc_drop_retable(upper('xc_qdpgtx_qdjl_dyqd_zxsj'),'ZHYW');
SQL_STRING:='create table zhyw.xc_qdpgtx_qdjl_dyqd_zxsj as
select a.* from 
(select a.片区归属区县,a.orgid,a.orgname,a.status,a.statusdate,a.unit_id,a.unit_name,
a.渠道类别,nvl(case when a.渠道类别 like ''%泛渠道%'' then ''否''end,''是'') 是否核心渠道,a.渠道经理工号,a.渠道经理,b.CREATDATE,
row_number() over (partition by a.orgid order by b.CREATDATE desc ) 排名  
from zhyw.shc_organization_'||v_monsr||' a,
(select * from  tbcs.ch_manager_allot@bcv b where b.status=''1'' ) b
where (a.status=1 or (a.status<>1 and a.statusdate>to_date('''||v_monsr||''',''yyyymm'')))
and a.orgid=b.orgid(+)
and a.渠道经理工号=b.EMPLOYEEID(+)
and a.是否自办渠道=''社会渠道''
and a.渠道类别 not in (''社会直销渠道'')
and a.渠道经理工号 is not null) a
where 排名=1 
----20230824 评估体系内包含校园渠道及市公司统管渠道,不应计入发展量,麻烦沙工全量剔除
and a.orgid not in (select orgid from zhyw.xc_qdpgtx_xiaoyuan_tongguan )  ';
EXECUTE IMMEDIATE (SQL_STRING);

----渠道经理对应渠道关系
zhyw.shc_drop_retable(upper('xc_qdpgtx_allqd_dyqd_zxsj'),'ZHYW');
SQL_STRING:='create table zhyw.xc_qdpgtx_allqd_dyqd_zxsj as
select a.* from 
(select a.片区归属区县,a.orgid,a.orgname,a.status,a.statusdate,a.unit_id,a.unit_name,
a.渠道类别,nvl(case when a.渠道类别 like ''%泛渠道%'' then ''否''end,''是'') 是否核心渠道,a.渠道经理工号,a.渠道经理,b.CREATDATE,
row_number() over (partition by a.orgid order by b.CREATDATE desc ) 排名  
from zhyw.shc_organization_'||v_monsr||' a,
(select * from  tbcs.ch_manager_allot@bcv b where b.status=''1'' ) b
where a.orgid=b.orgid(+)
and a.渠道经理工号=b.EMPLOYEEID(+)
and a.是否自办渠道=''社会渠道''
and a.渠道经理工号 is not null) a
where 排名=1 
----20230824 评估体系内包含校园渠道及市公司统管渠道,不应计入发展量,麻烦沙工全量剔除
and a.orgid not in (select orgid from zhyw.xc_qdpgtx_xiaoyuan_tongguan )  ';
EXECUTE IMMEDIATE (SQL_STRING);


-------------------------------------------各业务情况
---新入网
--(1)剔除当月停机、未活跃明细,未活跃客户定义:当月无语音或流量等通信业务。
--(2)拉新客户按照1:1.2计入,拉新口径为身份证名下6个月内未办理山东移动号码,融合拉新客户全部按照拉新客户计入。
--(3)新入网的号码需划归到C2D类集团内,未划归集团的不计入。---------分两部分,有的不限制
---折后49+
--(1)折后49元及以上套餐均计入折后49+,校园卡不计入。
--(2)折前129+按照1.5户折算。
--(3)剔除首月预存费用低于折后套餐费客户,后付费套餐不稽核该条件。
--(4)剔除当月停机、未活跃客户。

zhyw.shc_drop_retable(upper('xc_qdpgtx_gywmx_fanghao'),'ZHYW');
SQL_STRING:='create table zhyw.xc_qdpgtx_gywmx_fanghao as
select a.servnumber,a.subsid,a.qx_rg,a.registerorgid,a.createdate,a.status,a.prodid,a.prodname,b.PREPAYTYPE,
nvl(case when b.PREPAYTYPE=''pptpPre'' then ''预付费'' end,''后付费'') 付费类型,
a.unit_id,a.unit_name,shc.shc_func_stopkey(a.stopkey) stopkey,a.recopid,a.opername,a.oid,a.formnum,a.recdate,a.recorgid,
a.直销员电话,a.集团编号, 集团类型,nvl(case when nvl(upper(集团类型),''0'') like ''%C2%'' 
or nvl(upper(集团类型),''0'') like ''%D%'' then 1 end,0) 划归C2D类集团,
携入类型, 是否活跃, 是否拉新,
nvl(case when a.携入类型 is null then ''否'' end,''是'') 融合拉新,
产品归档,nvl(a.预存款价值,0) 预存款价值, nvl(a.当月充值金额,0)+nvl(a.预存款价值,0) 当月缴费金额,nvl(a.jiazhi,0) jiazhi,折后价值
from  zhyw.shc_fanghao_'||v_monsr||' a,
 tbcs.product_define@bcv b
 where a.prodid=b.prodid(+)
 and a.STATUS in (''US10'') 
 and a.是否活跃=1
 ----2023年8月1日 (周二) 13:43 徐策邮件 :电渠不算
 and a.registerorgid not like ''SD.LC.DQ%'' 
 and a.registerorgid not like ''SD.LC.YJDQ%''
 and to_char(a.createdate,''yyyymm'')='''||v_monsr||'''
and a.createdate-1 =129 then 1.5 end,1) 渠道社区_核算数,
nvl(case when a.jiazhi>=129 then 1.5 end,1)*a.划归c2d类集团  政企_核算数
from zhyw.xc_qdpgtx_gywmx_fanghao a 
where nvl(a.折后价值,0)>=48 
and a.产品归档 not in (''校园卡'')
--(3)剔除首月预存费用低于折后套餐费客户,后付费套餐不稽核该条件。
and (a.付费类型=''后付费'' or (a.付费类型=''预付费'' and a.当月缴费金额>=a.折后价值))  ';
EXECUTE IMMEDIATE (SQL_STRING);


zhyw.shc_drop_retable(upper('xc_qdpgtx_gywmx_zh49_zba'),'ZHYW');
SQL_STRING:='create table zhyw.xc_qdpgtx_gywmx_zh49_zba as
 select a.*,b.渠道类别,b.是否核心渠道,b.渠道经理工号,b.渠道经理 
  from zhyw.xc_qdpgtx_gywmx_zh49 a,
  zhyw.xc_qdpgtx_qdjl_dyqd_zxsj b
  where a.registerorgid=b.orgid ';
EXECUTE IMMEDIATE (SQL_STRING);

  zhyw.shc_drop_retable(upper('xc_qdpgtx_gywmx_zh49_hzjg'),'ZHYW');
  SQL_STRING:='create table zhyw.xc_qdpgtx_gywmx_zh49_hzjg as
  select '''||p_day||''' cycle, a.渠道经理工号,a.渠道经理,a.registerorgid,a.渠道类别,a.是否核心渠道,count(*) 条数, sum(a.渠道社区_核算数) 总结算数
  from zhyw.xc_qdpgtx_gywmx_zh49_zba a
  group by a.渠道经理工号,a.渠道经理,a.registerorgid,a.渠道类别,a.是否核心渠道 ';
  EXECUTE IMMEDIATE (SQL_STRING);

SQL_STRING:='delete zhyw.xc_qdpgtx_gywmx_zh49_hzjg_bdcd a where a.cycle='''||P_DAY||'''   ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;

SQL_STRING:='insert into zhyw.xc_qdpgtx_gywmx_zh49_hzjg_bdcd 
 select * from zhyw.xc_qdpgtx_gywmx_zh49_hzjg  ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;

----5G终端
--(1)终端合约:5G终端合约为泛全联盟统一平台供货的5G手机销量(包含直营、直供),具体指泛全联盟5G终端合约销量,包含信用购、顺差让利、5G金币等合约形式。
--(2)质量管控:终端合约顺差让利机卡分离不计入,数据取自《手机IMEI出库口径销售明细》 。
--(3)2G客户迁转:考核2G终端拍照客户完成迁转,2G客户迁转进度按照2G迁转5G完成率进行系数折算。

zhyw.shc_drop_retable(upper('xc_qdpgtx_gywmx_5gzd_zb'),'ZHYW');
SQL_STRING:='create table zhyw.xc_qdpgtx_gywmx_5gzd_zb as
select distinct a.imei,a.luru_subsid user_id,substr(a.sale_channel_id,8,1) QX_RG,
a.sale_channel_id,a.recdate CREATEDATE,b.status,b.prodid,pp.prodname,pd.PREPAYTYPE,
nvl(case when pd.PREPAYTYPE=''pptpPre'' then ''预付费'' end,''后付费'') 付费类型,u.town_id UNIT_ID,ut.unit_name,
shc.shc_func_stopkey(b.stopkey) stopkey,a.recopid,op.opername,a.recoid,''0'' FORMNUM,a.recdate,
a.sale_channel_id RECORGID,b5.zhixiao_hm 直销员电话,a.集团编号,a.集团类型,
nvl(case when nvl(upper(a.集团类型),''0'') like ''%C2%'' or nvl(upper(a.集团类型),''0'') like ''%D%'' then 1 end,0) 划归C2D类集团,
b6.入网类型 携入类型,nvl(b6.是否活跃,0) 是否活跃,''否''是否拉新,
nvl(case when nvl(upper(b6.入网类型),''0'') like ''%转入%'' then ''是'' end,''否'') 融合拉新,
a.term_brand||a.term_code 产品归档,a.录入号码套餐价值, 录入号码前三月平均ARPU, ZUIDIXIAOFEI,a.录入号码上月套餐价值,''5G终端'' type,
a.activity_id,a.activity_lvl_id,a.active_prodname,a.xieyi_privname,a.机卡分离
from (select a.*,row_number() over (partition by a.imei,a.recoid  order by a.recdate desc ) 排名 
from zhyw.LSHT_zibo_term_sale'||v_monsr||' a
where imei in (select imei from zibo.zb_term_fanquan_develop_mx )) a,
zhyw.subscriber b,
tbcs.product@bcv pp,
 tbcs.product_define@bcv pd,
 zibo.dw_user_town_ds_'||p_day||' u,
 zibo.DIM_PUB_UNIT ut,
 tbcs.operator@bcv op,
  zhyw.cs_order_contact  b5,
  zhyw.shc_all_label_mx b6 
----2023年8月1日 (周二) 13:43 徐策邮件 :电渠不算
where a.luru_subsid=b.subsid(+)
and b.prodid=pp.prodid(+)
and b.prodid=pd.prodid(+)
and a.luru_subsid=u.user_id(+)
and u.town_id=ut.unit_id(+)
and a.recopid=op.operid(+)
and a.recoid=b5.oid(+)
and a.luru_subsid=b6.subsid(+)
 and a.SALE_CHANNEL_ID not like ''SD.LC.DQ%'' 
 and a.SALE_CHANNEL_ID not like ''SD.LC.YJDQ%''
 and a.排名=1
 --and a.终端类型=''5GMoile''
 and to_char(a.RECDATE,''yyyymm'')='''||v_monsr||'''
 and a.RECDATE-1 =1  ';
 EXECUTE IMMEDIATE (SQL_STRING);

 zhyw.shc_drop_retable(upper('xc_qdpgtx_gywmx_2gqz_zba'),'ZHYW');
SQL_STRING:='create table ZHYW.xc_qdpgtx_gywmx_2gqz_zba as
  select * from
(select a.product_no,a.imei14,a.cycle,row_number() over (partition by a.product_no  order by a.cycle desc,count(*) desc) 排名  
 from shzc.lw_wzjk_zhsy_bdcd a where a.imei14 is not null 
and exists (select 1 from ZHYW.xc_qdpgtx_gywmx_2gqz_zb b where b.product_no=a.product_no )
group by a.product_no,a.imei14,a.cycle) a
where 排名=1 ';
 EXECUTE IMMEDIATE (SQL_STRING);
 
 zhyw.shc_drop_retable(upper('xc_qdpgtx_gywmx_2gqz_zbb'),'ZHYW');
SQL_STRING:='create table ZHYW.xc_qdpgtx_gywmx_2gqz_zbb as
select a.product_no,a.user_id,a.qx_gs county_id,a.unit_id_gs unit_id,zs flag,''0''is_jt_tac,''0''kacao,
a.type_final type_name,''0''open_volte_flag,''0''use_volte_flag,''0'' volte_flag, b.imei14,b.cycle,c.term_brand,c.term_code,c.band_4g,c.term_5g,
d.sale_channel_id,d.res_type_id,d.工号,d.终端类型,d.recoid,d.recdate,d.luru_servnumber,d.luru_subsid,d.集团编号,d.集团类型,
d.activity_id,d.active_prodname,d.activity_lvl_id,d.录入号码套餐价值,d.zuidixiaofei,d.xieyi_privname,d.机卡分离,d.录入号码上月套餐价值,
 录入号码前三月平均ARPU,d.recopid
from  ZHYW.xc_qdpgtx_gywmx_2gqz_zb a,
 ZHYW.xc_qdpgtx_gywmx_2gqz_zba b,
 ZIBO.DW_IMEI_TERMINFO_NEW_MS c,
 zhyw.LSHT_zibo_term_sale'||v_monsr||' d
 where a.product_no=b.product_no(+)
 and substr(b.imei14,1,8)=c.tac(+)
 and b.imei14=substr(d.imei,1,14) ';
 EXECUTE IMMEDIATE (SQL_STRING);
 
 
 zhyw.shc_drop_retable(upper('xc_qdpgtx_gywmx_2gqz_zbc'),'ZHYW');
SQL_STRING:='create table ZHYW.xc_qdpgtx_gywmx_2gqz_zbc as
 select distinct a.imei14,a.user_id,substr(a.sale_channel_id,8,1) QX_RG,
a.sale_channel_id,a.recdate CREATEDATE,b.status,b.prodid,pp.prodname,pd.PREPAYTYPE,
nvl(case when pd.PREPAYTYPE=''pptpPre'' then ''预付费'' end,''后付费'') 付费类型,u.town_id UNIT_ID,ut.unit_name,
shc.shc_func_stopkey(b.stopkey) stopkey,a.recopid,op.opername,a.recoid,''0'' FORMNUM,a.recdate,
a.sale_channel_id RECORGID,b5.zhixiao_hm 直销员电话,a.集团编号,a.集团类型,
nvl(case when nvl(upper(a.集团类型),''0'') like ''%C2%'' or nvl(upper(a.集团类型),''0'') like ''%D%'' then 1 end,0) 划归C2D类集团,
b6.入网类型 携入类型,nvl(b6.是否活跃,0) 是否活跃,''否''是否拉新,
nvl(case when nvl(upper(b6.入网类型),''0'') like ''%转入%'' then ''是'' end,''否'') 融合拉新,
a.term_brand||a.term_code 产品归档,a.录入号码套餐价值, 录入号码前三月平均ARPU, ZUIDIXIAOFEI,a.录入号码上月套餐价值,''2G迁转'' type,
a.activity_id,a.activity_lvl_id,a.active_prodname,a.xieyi_privname,a.机卡分离,a.flag,a.band_4g,a.term_5g 
 from ZHYW.xc_qdpgtx_gywmx_2gqz_zbb a,
 zhyw.subscriber b,
tbcs.product@bcv pp,
 tbcs.product_define@bcv pd,
 zibo.dw_user_town_ds_'||P_DAY||' u,
 zibo.DIM_PUB_UNIT ut,
 tbcs.operator@bcv op,
  zhyw.cs_order_contact  b5,
  zhyw.shc_all_label_mx b6 
----2023年8月1日 (周二) 13:43 徐策邮件 :电渠不算
where a.luru_subsid=b.subsid(+)
and b.prodid=pp.prodid(+)
and b.prodid=pd.prodid(+)
and a.luru_subsid=u.user_id(+)
and u.town_id=ut.unit_id(+)
and a.工号=op.operid(+)
and a.recoid=b5.oid(+)
and a.luru_subsid=b6.subsid(+)
and a.终端类型=''5GMoile''
 and to_char(a.RECDATE,''yyyymm'')='''||v_monsr||'''
 and a.RECDATE-1 to_date('''||v_monsr||''',''yyyymm'')
and nvl(e.startdate,sysdate+9999)to_date('''||v_monsrh||''',''yyyymm'')
and nvl(e.startdate,sysdate+9999)sysdate then ''1'' end flag_htv,
 case when k16.in_subsid is not null  then ''同址换号'' end flag_huanhao ,
 case when k17.user_id is not null then ''c类宽带'' end c类 ,
  k12.unit_name unit_namek12,
 case when k18.AFFECTTYPE=2 then ''当月生效'' when k18.AFFECTTYPE=3 then ''次月生效'' else to_char(k18.affecttype,0) end 生效月份,
 zhixiao_hm ,k19.zhixiao_name ,a.APPLYOID
  
from   zhyw.'||V_TAB1||' a,
      zhyw.qcy_tmp_unit_grid a1,
      zhyw.zb_yxkd_county b ,
      zhyw.zhai_htv_subsxin c ,
      --ZHYW.zhht_kd_om_order1 F,
       (select * from zhyw.dict_item m where groupid=''US'') f1, ZHYW.ZHAI_PQ_KD_DIM g,
   zhyw.zb_wnfk_subs k1,
  zhyw.zb_subs_tc_jiazhi k6,
  zhyw.zb_yxkd_xufei_subs k7,
  zhyw.wanneng_fk_mb_mx  k8 ,
  zhyw.zb_kd_aijia_qunzu_subs k9,
  zhyw.zb_yxkd_flow_'||v_monsr||' k10,
  zhyw.'||V_TAB2||' k11,
  zhyw.shc_organization k12,
  zhyw.zb_yxkd_cancel_reason_subs  k13,
  (select   item,subsid,privid,privname,a.startdate,a.enddate
    from zhyw.qcy_tmp_kd_prv_2 a
   where item=''产品资费'' and
         nvl(enddate,sysdate+10000)>sysdate-1
    ) k14,
(select   subsid,privid,privname,startdate,enddate
 from zhyw.qcy_tmp_kd_photo_2
where  nvl(enddate,sysdate+10000)>sysdate-1
) k15, ---宽带优惠到期
zhyw.ZB_YXKD_HUANHAO_SUBS k16,
zibo.d_notbroadband_user_ds k17,
 zhyw.SHC_SUBS_PRODUCT k18,
 zhyw.cs_order_contact k19 

where   a.所属区县=b.所属区县(+)  and
             a.grid_id=a1.grid_id(+) and
      a.subsid=c.subsid(+) --and a.servnumber=F.acc_num(+) 
      AND a.status=f1.dictid(+) and nvl(a.订单状态,''0'')<>''已撤单'' and nvl(a.lx_priv,''0'')<>''铁通天''
and a.所属小区_学校_自然村=g.boss小区编码(+)
and a.subsid=k1.main_subsid(+) and
a.subsid=k6.subsid(+) and
a.subsid=k7.subsid(+) and
a.subsid=k8.subsid(+) and
a.subsid=k9.subsid(+) and
a.subsid=k10.user_id(+) and 
a.subsid=k11.subsid(+) and
a.recorgid=k12.orgid(+) and
a.subsid=k13.subsid(+)  and
a.subsid=k14.subsid(+)  and
a.subsid=k15.subsid(+) and 
a.subsid=k16.in_subsid(+) and 
a.subsid=k17.user_id(+)  and 
a.subsid=k18.subsid(+) and 
a.prodid_fw=k18.prodid(+)  and 
a.applyoid=k19.oid(+) 
and to_char(a.startdate,''yyyymm'')='''||v_monsr||'''
and a.startdate-1 =30 then 1
          when a.是否核心渠道=''否'' and to_number(nvl(regexp_substr(a.zzsc,''+[0-9]+''),0))>=10 then 1 end,0)=1 ) a
where 排名<3
group by a.res_id,a.res_name,a.渠道经理工号,a.渠道经理,a.是否核心渠道,a.渠道类别 ' ;
    execute immediate (SQL_STRING);


zhyw.shc_drop_retable(upper('xc_qdpgtx_qdzf_hxfqd_zbc'),'ZHYW');
SQL_STRING:='create table ZHYW.xc_qdpgtx_qdzf_hxfqd_zbc  as
select a.*,nvl(b.走访次数,0) 走访次数,nvl(b.走访天数,0) 走访天数 
from  zhyw.xc_qdpgtx_qdjl_dyqd_zxsj a,
 ZHYW.xc_qdpgtx_qdzf_hxfqd_zbb b
 where a.orgid=b.res_id(+) ' ;
    execute immediate (SQL_STRING);

zhyw.shc_drop_retable(upper('xc_qdpgtx_qdzf_hxfqd_zbd'),'ZHYW');
SQL_STRING:='create table ZHYW.xc_qdpgtx_qdzf_hxfqd_zbd  as
select a.渠道经理工号,a.渠道经理,count(distinct a.orgid) 渠道总量,
count(distinct case when a.是否核心渠道=''是'' then a.orgid end) 核心渠道数,
count(distinct case when a.是否核心渠道=''是'' and a.走访次数>0 then a.orgid end) 核心渠道走访数,
count(distinct case when a.是否核心渠道=''是'' and a.走访次数>=8 then a.orgid end) 核心渠道有效走访数,
round(count(distinct case when a.是否核心渠道=''是'' and a.走访次数>=8 then a.orgid end)/
decode(count(distinct case when a.是否核心渠道=''是'' then a.orgid end),0,1,count(distinct case when a.是否核心渠道=''是'' then a.orgid end))*100,2) 核心渠道有效走访率,
count(distinct case when a.是否核心渠道=''否'' then a.orgid end) 泛渠道数,
count(distinct case when a.是否核心渠道=''否'' and a.走访次数>=1 then a.orgid end) 泛渠道有效走访数,
round(count(distinct case when a.是否核心渠道=''否'' and a.走访次数>=1 then a.orgid end)/
decode(count(distinct case when a.是否核心渠道=''否'' then a.orgid end),0,1,count(distinct case when a.是否核心渠道=''否'' then a.orgid end))*100,2) 泛渠道有效走访率
from ZHYW.xc_qdpgtx_qdzf_hxfqd_zbc a 
group by a.渠道经理工号,a.渠道经理 ' ;
    execute immediate (SQL_STRING);


zhyw.shc_drop_retable(upper('xc_qdpgtx_qdzf_hxfqd_hzjg'),'ZHYW');
SQL_STRING:='create table ZHYW.xc_qdpgtx_qdzf_hxfqd_hzjg  as
select '''||p_day||''' cycle, a.*,round((a.核心渠道有效走访数+a.泛渠道有效走访数)/a.渠道总量*100,2) 渠道总量有效走访率
from ZHYW.xc_qdpgtx_qdzf_hxfqd_zbd a ' ;
    execute immediate (SQL_STRING);


SQL_STRING:='delete zhyw.xc_qdpgtx_qdzf_hxfqd_hzjg_bdcd a where a.cycle='''||P_DAY||'''   ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;

SQL_STRING:='insert into ZHYW.xc_qdpgtx_qdzf_hxfqd_hzjg_bdcd 
select * from ZHYW.xc_qdpgtx_qdzf_hxfqd_hzjg    ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;


---核心渠道高销率  商渠泛渠道活跃率
--考核核心渠道有效业务20笔及以上达标率,有效业务包含放号、存量、家庭、5G终端合约月销量≥20笔。
--考核商渠泛渠道有效业务活跃率,有效业务包含有效业务包含放号、存量、家庭、5G终端合约等重点业务。

--家庭业务 指 宽带、htv、家庭安防、路由器(智能组网)、点播年包

---魔百和_点播明细

 select max(table_name) into V_TAB1 FROM  all_tables  where table_name like upper('%DW_MBH_USER_HY_FLAG_20%')  and owner='ZIBO';
 select to_char(max(op_time),'yyyymmdd') into V_TAB2  from zibo.DW_MBH_USER_ANDTV_SPLX_DM;


zhyw.shc_drop_retable(upper('xc_qdpgtx_qdhyl_mbhdb'),'ZHYW');
SQL_STRING:='create table ZHYW.xc_qdpgtx_qdhyl_mbhdb as
select  distinct  a.county_id,b2.unit_name,rec_qx,k.grid_name, a.servnumber,a.subsid,bizcode,vc_bizname,applyoperid,dictname,
a.recdate,b1.orgname,flag_nb,price,a.recorgid,a.orgname orgnamea,
                 startdate,enddate ,hm_status,所属区县名称,flag_red,flag_app,   ''否''  可兑换,
                 sp_name,sp_start,sp_end,sp_canceloperid  ,
                 htv_start ,htv_end,
                 kd_start ,kd_end,
                 KD_QX,  FLAG_XF, XF_START,  XF_END,  XF_PRIV  ,xf_price,XF_OPERID,  XF_QX,  XF_ORG,
                 db_time   点播播放时长,
              tz_time    赛特斯探针原始收视时长,
             zmdj_cs   桌面点击次数,
              hy_flag     用户当月是否活跃,
              b3.playtime_xd_m 有效播放时长_分钟,
              b4.note,a.tc_priv,a.jiazhi,FLAG_MIDHIGH ,
              b5.zhixiao_hm,b5.zhixiao_name ,a.applyoid
   from zhyw.zb_htv_spservice_subs a,
            zhyw.zb_yyy_unit  k,
           zibo.'||V_TAB1||' a1 ,
            ( select b.orgname,a.oid from zhyw.shc_reception a, zhyw.organization b
             where a.recorgid=b.orgid(+)
             ) b1,
           zhyw.zb_grid_subs b2 ,
          ( select   product_no,sum(playtime_xd_m ) playtime_xd_m
            from zibo.DW_MBH_USER_ANDTV_SPLX_DM
           where playtime_xd_m>0.05  and to_char(op_time,''yyyymmdd'')='''||V_TAB2||'''
           group by product_no   )  b3,
            (select *From qcy.qcy_htv_nb_priv where note=''接盘优惠'')b4,
             zhyw.cs_order_contact  b5       
  where  a.applyoperid=k.operid(+)  and
                a.subsid=a1.user_id(+)  and
                a.applyoid=b1.oid(+) and
                a.subsid=b2.subsid(+) and 
                a.servnumber=b3.product_No(+) and
                a.bizcode=b4.privid(+) and
                a.applyoid=b5.oid(+) 
                and to_char(a.startdate,''yyyymm'')='''||v_monsr||'''
                and a.startdate-1 =20 then 1 
                     when a.是否核心渠道=''否'' and 业务量>=1 then 1 end,0) 是否达标
 from 
 (select a.registerorgid,a.渠道类别,a.是否核心渠道,a.渠道经理工号,a.渠道经理,
 count(distinct a.subsid||a.oid||a.type||a.dalei) 业务量
 from
 (select * from ZHYW.xc_qdpgtx_qdhyl_fhyw a
 union all 
 select * from ZHYW.xc_qdpgtx_qdhyl_zdyw a
 union all
 select * from ZHYW.xc_qdpgtx_qdhyl_jtyw a) a
 group by a.registerorgid,a.渠道类别,a.是否核心渠道,a.渠道经理工号,a.渠道经理) a  ';
      EXECUTE IMMEDIATE (SQL_STRING);


 zhyw.shc_drop_retable(upper('xc_qdpgtx_qdhyl_qdjlgl'),'ZHYW');
 SQL_STRING:='create table ZHYW.xc_qdpgtx_qdhyl_qdjlgl as
 select a.渠道经理工号,a.渠道经理,
 count(distinct case when a.是否核心渠道=''是'' then a.orgid end) 核心渠道数,
 count(distinct case when a.是否核心渠道=''否'' then a.orgid end) 泛渠道数
 from zhyw.xc_qdpgtx_qdjl_dyqd_zxsj a 
 group by a.渠道经理工号,a.渠道经理 ';
 EXECUTE IMMEDIATE (SQL_STRING);
 
 
 zhyw.shc_drop_retable(upper('xc_qdpgtx_qdhyl_qdjldb'),'ZHYW');
 SQL_STRING:='create table ZHYW.xc_qdpgtx_qdhyl_qdjldb as
 select a.渠道经理工号,a.渠道经理,
 count(distinct case when a.是否核心渠道=''是'' and a.是否达标=1 then a.registerorgid end) 核心渠道达标数,
 count(distinct case when a.是否核心渠道=''否'' and a.是否达标=1 then a.registerorgid end) 泛渠道达标数
 from ZHYW.xc_qdpgtx_qdhyl_allhz a
 group by a.渠道经理工号,a.渠道经理';
 EXECUTE IMMEDIATE (SQL_STRING);
 
  zhyw.shc_drop_retable(upper('xc_qdpgtx_qdhyl_jlhzjg'),'ZHYW');
 SQL_STRING:='create table ZHYW.xc_qdpgtx_qdhyl_jlhzjg as
 select a.渠道经理工号,a.渠道经理,
 a.核心渠道数,nvl(b.核心渠道达标数,0) 核心渠道达标数,
 round(nvl(b.核心渠道达标数,0)/decode(a.核心渠道数,0,1,a.核心渠道数)*100,2) 核心渠道达标率,
 a.泛渠道数,nvl(b.泛渠道达标数,0) 泛渠道达标数,
 round(nvl(b.泛渠道达标数,0)/decode(a.泛渠道数,0,1,a.泛渠道数)*100,2) 泛渠道达标率
 from ZHYW.xc_qdpgtx_qdhyl_qdjlgl a,
  ZHYW.xc_qdpgtx_qdhyl_qdjldb b
  where a.渠道经理工号=b.渠道经理工号(+)';
 EXECUTE IMMEDIATE (SQL_STRING);


---数据组合


 zhyw.shc_drop_retable(upper('xc_qdpgtx_qdjl_zdcn_rhz'),'ZHYW');
 SQL_STRING:='create table ZHYW.xc_qdpgtx_qdjl_zdcn_rhz as
 select a.cycle,
        g.orgid,q.orgname,q.unit_id,q.unit_name,
        a.渠道经理工号,
        a.渠道经理,
        b.核心渠道数,
        b.泛渠道数,
        a.总_条数,
        a.总_结算数,
        a.新入网_条数,
        a.新入网_结算数,
        a.折后49_条数,
        a.折后49_结算数,
        a.升档_条数,
        a.升档_结算数,
        a.g5终端_条数,
        a.g5终端_结算数,
        a.g2迁转_条数,
        a.g2迁转_结算数,
        a.g2转g5_条数,
        a.g2转g5_结算数,
        a.线盒新增_条数,
        a.线盒新增_结算数,
 c.核心渠道达标数,c.核心渠道达标率,
 c.泛渠道达标数,c.泛渠道达标率,
 nvl(y.channels,0) 清退渠道数,nvl((y.totalval+y.depositval),0)/100 清退押金,
 z.核心渠道走访数, z.核心渠道有效走访数, z.核心渠道有效走访率,  
 z.泛渠道有效走访数, z.泛渠道有效走访率, 
 z.渠道总量有效走访率
 from zhyw.xc_qdpgtx_qdyw_zdcn_hz a,
 ZHYW.xc_qdpgtx_qdhyl_qdjlgl b,
 ZHYW.xc_qdpgtx_qdhyl_qdjldba c,
  zhyw.xc_qdpgtx_qdyj_qtjl_hzjg y,
  ZHYW.xc_qdpgtx_qdzf_hxfqd_hzjg z,
   tbcs.operator@Bcv g,
   zhyw.shc_organization_'||v_monsr||' q
 where a.渠道经理工号=b.渠道经理工号(+)
 and a.渠道经理工号=c.渠道经理工号(+)
 and a.渠道经理工号=y.employeeid(+)
 and a.渠道经理工号=z.渠道经理工号(+)
 and a.渠道经理工号=g.operid(+)
 and g.orgid=q.orgid(+)';
 EXECUTE IMMEDIATE (SQL_STRING);


--渠道经理目标
 zhyw.shc_drop_retable(upper('xc_qdpgtx_qdjl_zdcn_rhzjg'),'ZHYW');
 SQL_STRING:='create table ZHYW.xc_qdpgtx_qdjl_zdcn_rhzjg as
select a.cycle,
       a.orgid,
       a.orgname,
       a.unit_id,
       a.unit_name,
       a.渠道经理工号,
       a.渠道经理,
       a.核心渠道数,
       a.泛渠道数,
       a.总_条数,
       a.总_结算数,
       a.新入网_条数,
       a.新入网_结算数,nvl(b.hx_xrw,0) 新入网_目标,
       a.折后49_条数,
       a.折后49_结算数,nvl(b.hx_zh49,0) 折后49_目标,
       a.升档_条数,
       a.升档_结算数,nvl(b.hx_sd,0) 升档_目标,
       a.g5终端_条数,
       a.g5终端_结算数,nvl(b.hx_5gzd,0) g5终端_目标,
       a.g2迁转_条数,
       a.g2迁转_结算数,nvl(b.hx_2gqz,0) g2迁转_目标,
       a.g2转g5_条数,
       a.g2转g5_结算数,nvl(b.hx_2gq5g,0) g2转g5_目标,
       a.线盒新增_条数,
       a.线盒新增_结算数,nvl(b.hx_xhxz,0) 线盒新增_目标,
       
       
       a.核心渠道达标数,
       a.核心渠道达标率,nvl(b.hx_hxqdgxl,0) 核心渠道高销率_目标,
       a.泛渠道达标数,
       a.泛渠道达标率,nvl(b.hx_sqfqdhyl,0) 商渠泛渠道活跃率_目标,
       a.清退渠道数,
       a.清退押金,nvl(b.hx_bzjqt,0) 保证金清退_目标,
       a.核心渠道走访数,
       a.核心渠道有效走访数,
       a.核心渠道有效走访率,
       a.泛渠道有效走访数,
       a.泛渠道有效走访率,
       a.渠道总量有效走访率,nvl(b.hx_qdzf,0)*100 渠道走访_目标
from ZHYW.xc_qdpgtx_qdjl_zdcn_rhz a,
 zhyw.xc_qdpgtx_qdjl_mbsj_zxsj b
where a.渠道经理=b.qdjl(+)';
 EXECUTE IMMEDIATE (SQL_STRING);


  zhyw.shc_drop_retable(upper('xc_qdpgtx_qdzg_zdcn_rhz'),'ZHYW');
 SQL_STRING:='create table ZHYW.xc_qdpgtx_qdzg_zdcn_rhz as
select a.cycle,substr(a.orgid,1,8) qx_id,
 sum(nvl(核心渠道数,0)) 核心渠道数,
sum(nvl(泛渠道数,0)) 泛渠道数,
sum(nvl(总_条数,0)) 总_条数,
sum(nvl(总_结算数,0)) 总_结算数,
sum(nvl(新入网_条数,0)) 新入网_条数,
sum(nvl(新入网_结算数,0)) 新入网_结算数,
sum(nvl(折后49_条数,0)) 折后49_条数,
sum(nvl(折后49_结算数,0)) 折后49_结算数,
sum(nvl(升档_条数,0)) 升档_条数,
sum(nvl(升档_结算数,0)) 升档_结算数,
sum(nvl(G5终端_条数,0)) G5终端_条数,
sum(nvl(G5终端_结算数,0)) G5终端_结算数,
sum(nvl(G2迁转_条数,0)) G2迁转_条数,
sum(nvl(G2迁转_结算数,0)) G2迁转_结算数,
sum(nvl(G2转G5_条数,0)) G2转G5_条数,
sum(nvl(G2转G5_结算数,0)) G2转G5_结算数,
sum(nvl(线盒新增_条数,0)) 线盒新增_条数,
sum(nvl(线盒新增_结算数,0)) 线盒新增_结算数,
sum(nvl(核心渠道达标数,0)) 核心渠道达标数,
round(sum(nvl(核心渠道达标数,0))/ decode(sum(nvl(核心渠道数,0)),0,1,sum(nvl(核心渠道数,0))) *100,2) 核心渠道达标率,
sum(nvl(泛渠道达标数,0)) 泛渠道达标数,
round(sum(nvl(泛渠道达标数,0))/ decode(sum(nvl(泛渠道数,0)),0,1,sum(nvl(泛渠道数,0))) *100,2) 泛渠道达标率,
sum(nvl(清退渠道数,0)) 清退渠道数,
sum(nvl(清退押金,0)) 清退押金,
sum(nvl(核心渠道走访数,0)) 核心渠道走访数,
sum(nvl(核心渠道有效走访数,0)) 核心渠道有效走访数,
sum(nvl(核心渠道有效走访率,0)) 核心渠道有效走访率,
sum(nvl(泛渠道有效走访数,0)) 泛渠道有效走访数,
sum(nvl(泛渠道有效走访率,0)) 泛渠道有效走访率,
sum(nvl(渠道总量有效走访率,0)) 渠道总量有效走访率
from ZHYW.xc_qdpgtx_qdjl_zdcn_rhz a 
group by a.cycle,substr(a.orgid,1,8)
union all
select a.cycle,''SD.LC'' qx_id,
 sum(nvl(核心渠道数,0)) 核心渠道数,
sum(nvl(泛渠道数,0)) 泛渠道数,
sum(nvl(总_条数,0)) 总_条数,
sum(nvl(总_结算数,0)) 总_结算数,
sum(nvl(新入网_条数,0)) 新入网_条数,
sum(nvl(新入网_结算数,0)) 新入网_结算数,
sum(nvl(折后49_条数,0)) 折后49_条数,
sum(nvl(折后49_结算数,0)) 折后49_结算数,
sum(nvl(升档_条数,0)) 升档_条数,
sum(nvl(升档_结算数,0)) 升档_结算数,
sum(nvl(G5终端_条数,0)) G5终端_条数,
sum(nvl(G5终端_结算数,0)) G5终端_结算数,
sum(nvl(G2迁转_条数,0)) G2迁转_条数,
sum(nvl(G2迁转_结算数,0)) G2迁转_结算数,
sum(nvl(G2转G5_条数,0)) G2转G5_条数,
sum(nvl(G2转G5_结算数,0)) G2转G5_结算数,
sum(nvl(线盒新增_条数,0)) 线盒新增_条数,
sum(nvl(线盒新增_结算数,0)) 线盒新增_结算数,
sum(nvl(核心渠道达标数,0)) 核心渠道达标数,
round(sum(nvl(核心渠道达标数,0))/ decode(sum(nvl(核心渠道数,0)),0,1,sum(nvl(核心渠道数,0))) *100,2) 核心渠道达标率,
sum(nvl(泛渠道达标数,0)) 泛渠道达标数,
round(sum(nvl(泛渠道达标数,0))/ decode(sum(nvl(泛渠道数,0)),0,1,sum(nvl(泛渠道数,0))) *100,2) 泛渠道达标率,
sum(nvl(清退渠道数,0)) 清退渠道数,
sum(nvl(清退押金,0)) 清退押金,
sum(nvl(核心渠道走访数,0)) 核心渠道走访数,
sum(nvl(核心渠道有效走访数,0)) 核心渠道有效走访数,
sum(nvl(核心渠道有效走访率,0)) 核心渠道有效走访率,
sum(nvl(泛渠道有效走访数,0)) 泛渠道有效走访数,
sum(nvl(泛渠道有效走访率,0)) 泛渠道有效走访率,
sum(nvl(渠道总量有效走访率,0)) 渠道总量有效走访率
from ZHYW.xc_qdpgtx_qdjl_zdcn_rhz a 
group by a.cycle';
 EXECUTE IMMEDIATE (SQL_STRING);


 zhyw.shc_drop_retable(upper('xc_qdpgtx_qdzg_zdcn_rhzjg'),'ZHYW');
 SQL_STRING:='create table ZHYW.xc_qdpgtx_qdzg_zdcn_rhzjg as
SELECT A.CYCLE,b.county_id,
       A.QX_ID,b.qx,
       A.核心渠道数,
       A.泛渠道数,
       A.总_条数,
       A.总_结算数,
       A.新入网_条数,
       a.新入网_结算数,nvl(b.hx_xrw,0) 新入网_目标,
       a.折后49_条数,
       a.折后49_结算数,nvl(b.hx_zq69,0) 折后49_目标,
       a.升档_条数,
       a.升档_结算数,nvl(b.hx_sd,0) 升档_目标,
       a.g5终端_条数,
       a.g5终端_结算数,nvl(b.hx_5gzd,0) g5终端_目标,
       a.g2迁转_条数,
       a.g2迁转_结算数,nvl(b.hx_2gqz,0) g2迁转_目标,
       a.g2转g5_条数,
       a.g2转g5_结算数,nvl(b.hx_2gq5g,0) g2转g5_目标,
       a.线盒新增_条数,
       a.线盒新增_结算数,nvl(b.hx_xhxz,0) 线盒新增_目标,
       a.核心渠道达标数,
       a.核心渠道达标率,nvl(b.hx_hxqdgxl,0) 核心渠道高销率_目标,
       a.泛渠道达标数,
       a.泛渠道达标率,nvl(b.hx_sqfqdhyl,0) 商渠泛渠道活跃率_目标,
       a.清退渠道数,
       a.清退押金,nvl(b.hx_bzjqt,0) 保证金清退_目标,
       a.核心渠道走访数,
       a.核心渠道有效走访数,
       round(a.核心渠道有效走访数/核心渠道数*100,2) 核心渠道有效走访率,
       a.泛渠道有效走访数,
       round(泛渠道有效走访数/泛渠道数*100,2)  泛渠道有效走访率,
       round((a.核心渠道有效走访数+泛渠道有效走访数)/(核心渠道数+泛渠道数)*100,2) 渠道总量有效走访率
FROM ZHYW.xc_qdpgtx_qdzg_zdcn_rhz A,
zhyw.xc_qdpgtx_qdzg_mbsj_zxsj B
WHERE A.QX_ID=B.NOTE(+)';
 EXECUTE IMMEDIATE (SQL_STRING);



----渠道经理
SQL_STRING:='delete zhyw.xc_qdpgtx_qdjl_zdcn_rhz_bdcd a where a.cycle='''||P_DAY||'''   ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;

SQL_STRING:='insert into ZHYW.xc_qdpgtx_qdjl_zdcn_rhz_bdcd 
select * from ZHYW.xc_qdpgtx_qdjl_zdcn_rhzjg a  ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;

----渠道主管
SQL_STRING:='delete zhyw.xc_qdpgtx_qdzg_zdcn_rhz_bdcd a where a.cycle='''||P_DAY||'''   ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;

SQL_STRING:='insert into  ZHYW.xc_qdpgtx_qdzg_zdcn_rhz_bdcd 
select * from ZHYW.xc_qdpgtx_qdzg_zdcn_rhzjg a ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;

你可能感兴趣的:(数据库办公记录语句,数据库)