-------------2023-0522-近期多地使用号码情况
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_bd'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_bd as
select to_char(b.start_datetime-0.01,''yyyymmdd'') cycle,b.product_no,b.start_datetime,substr(b.imei,1,14) imei14,
b.roamcity_name,b.roamcity_id,b.lac_id,b.cell_id,b.huadan_typename,b.county_id,b.geo_longitude,b.geo_latitude,b.bts_name
from zibo.lw_sasz_xdjl_zhsy_bd b where to_char(b.start_datetime-0.01,''yyyymmdd'')=
(select max(to_char(b.start_datetime-0.01,''yyyymmdd'')) from zibo.lw_sasz_xdjl_zhsy_bd b ) ';
EXECUTE IMMEDIATE (SQL_STRING);
SQL_STRING:='insert into shzc.lw_wzjk_zhsy_bdcd
select a.cycle,
a.product_no,
a.start_datetime,
a.imei14,
nvl(nvl(a.roamcity_name,c1.areaname),c2.areaname) roamcity_name,
a.roamcity_id,
a.lac_id,
a.cell_id,
a.huadan_typename,
a.county_id,
a.bts_name
from shzc.lw_wzjk_zhsy_bd a,
(select * from common.SA_DB_NATAREAINFO@bcv c where c.AREATYPE=''1'') c1,
(select * from common.SA_DB_NATAREAINFO@bcv c where c.AREATYPE=''2'') c2
where a.roamcity_id=c1.areaid(+)
and a.roamcity_id=c2.areaid(+)
and not exists (select 1 from shzc.lw_wzjk_zhsy_bdcd t where t.cycle=a.cycle and t.product_no=a.product_no) ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_bd'),'SHZC');
----日期排序
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_rq'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_rq as
select a.cycle,row_number() over (partition by 1 order by a.cycle desc ) 排名
from shzc.lw_wzjk_zhsy_bdcd a
group by a.cycle ';
EXECUTE IMMEDIATE (SQL_STRING);
-----看不只在淄博使用的号码,近30天情况,漫出天数 地市为空的不计算
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_bd_tmp_cshz'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_bd_tmp_cshz as
select a.product_no,count(distinct a.roamcity_name) roamcity_names,count(distinct a.cycle) cycles,
max(nvl(case when a.roamcity_name in (''淄博'') then 1 end,0)) 是否淄博使用,
count(distinct case when a.roamcity_name not in (''淄博'') then a.roamcity_name end) 漫出地市数,
count(distinct case when a.roamcity_name not in (''淄博'') then a.cycle end) 漫出天数
from shzc.lw_wzjk_zhsy_bdcd a,
(select * from shzc.lw_wzjk_zhsy_fxzb_rq t where t.排名<=30 ) t
where a.cycle=t.cycle
and nvl(a.ROAMCITY_NAME,''0'')<>''0''
group by a.product_no ';
EXECUTE IMMEDIATE (SQL_STRING);
----可以增加号码索引 ----建索引
SQL_STRING:='create index shzc.lw_wzjk_cshz on shzc.lw_wzjk_zhsy_bd_tmp_cshz(product_no) ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;
----号码近30天每天使用地情况,1为最近一天,30为最早一天。
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mx'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_mx as
select a.product_no,count(distinct a.cycle) cycle,count(distinct a.provincename||a.roamcity_name) roamcity_name,
max(case when a.排名=1 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y1,
max(case when a.排名=2 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y2,
max(case when a.排名=3 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y3,
max(case when a.排名=4 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y4,
max(case when a.排名=5 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y5,
max(case when a.排名=6 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y6,
max(case when a.排名=7 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y7,
max(case when a.排名=8 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y8,
max(case when a.排名=9 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y9,
max(case when a.排名=10 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y10,
max(case when a.排名=11 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y11,
max(case when a.排名=12 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y12,
max(case when a.排名=13 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y13,
max(case when a.排名=14 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y14,
max(case when a.排名=15 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y15,
max(case when a.排名=16 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y16,
max(case when a.排名=17 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y17,
max(case when a.排名=18 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y18,
max(case when a.排名=19 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y19,
max(case when a.排名=20 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y20,
max(case when a.排名=21 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y21,
max(case when a.排名=22 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y22,
max(case when a.排名=23 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y23,
max(case when a.排名=24 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y24,
max(case when a.排名=25 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y25,
max(case when a.排名=26 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y26,
max(case when a.排名=27 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y27,
max(case when a.排名=28 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y28,
max(case when a.排名=29 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y29,
max(case when a.排名=30 then nvl(a.provincename,a.roamcity_name)||''_''||a.roamcity_name end) y30
from
(select a.*,b.排名
from
(select a.cycle,a.product_no,a.imei14,a.roamcity_name,a.roamcity_id,a.huadan_typename,
nvl(c1.AREATYPE,c2.AREATYPE) AREATYPE,
nvl(c1.PROVINCEID,c1.PROVINCEID) PROVINCEID,
nvl(c1.PROVINCENAME,c1.PROVINCENAME) PROVINCENAME
from shzc.lw_wzjk_zhsy_bdcd a,
(select * from common.SA_DB_NATAREAINFO@bcv c where c.AREATYPE=''1'') c1,
(select * from common.SA_DB_NATAREAINFO@bcv c where c.AREATYPE=''2'') c2,
shzc.lw_wzjk_zhsy_bd_tmp_cshz t
where a.roamcity_id=c1.areaid(+)
and a.roamcity_id=c2.areaid(+)
and a.product_no=t.product_no
and nvl(a.ROAMCITY_NAME,''0'')<>''0'') a,
(select * from shzc.lw_wzjk_zhsy_fxzb_rq b where b.排名<=30 ) b
where a.cycle=b.cycle) a
group by a.product_no ';
EXECUTE IMMEDIATE (SQL_STRING);
----可以增加号码索引 ----建索引
SQL_STRING:='create index shzc.lw_wzjk_mx on shzc.lw_wzjk_zhsy_fxzb_mx(product_no) ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;
----根据号码使用地最多天数进行汇总 ---排名
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_hz'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_hz as
select a.* from
(select a.product_no,PROVINCENAME,roamcity_name,count(distinct a.cycle) cycles,min(a.cycle) min_cycle,max(a.cycle) max_cycle,
row_number() over (partition by a.product_no order by count(distinct a.cycle) desc ) 排名
from
(select a.cycle,a.product_no,a.imei14,a.roamcity_name,a.roamcity_id,a.huadan_typename,
nvl(c1.AREATYPE,c2.AREATYPE) AREATYPE,
nvl(c1.PROVINCEID,c1.PROVINCEID) PROVINCEID,
nvl(c1.PROVINCENAME,c1.PROVINCENAME) PROVINCENAME
from shzc.lw_wzjk_zhsy_bdcd a,
(select * from shzc.lw_wzjk_zhsy_fxzb_rq b where b.排名<=30 ) b,
(select * from common.SA_DB_NATAREAINFO@bcv c where c.AREATYPE=''1'') c1,
(select * from common.SA_DB_NATAREAINFO@bcv c where c.AREATYPE=''2'') c2,
shzc.lw_wzjk_zhsy_bd_tmp_cshz t
where a.roamcity_id=c1.areaid(+)
and a.roamcity_id=c2.areaid(+)
and a.product_no=t.product_no
and a.cycle=b.cycle
and nvl(a.ROAMCITY_NAME,''0'') not in (''0'',''淄博'') ) a
group by a.product_no,PROVINCENAME,roamcity_name) a
where 排名<=3 ';
EXECUTE IMMEDIATE (SQL_STRING);
----可以增加号码索引 ----建索引
SQL_STRING:='create index shzc.lw_wzjk_hz on shzc.lw_wzjk_zhsy_fxzb_hz(product_no) ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;
----根据号码使用地最多天数进行汇总 ---淄博
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_zb'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_zb as
select a.product_no,PROVINCENAME,roamcity_name,count(distinct a.cycle) cycles,min(a.cycle) min_cycle,max(a.cycle) max_cycle,
row_number() over (partition by a.product_no order by count(distinct a.cycle) desc ) 排名
from
(select a.cycle,a.product_no,a.imei14,a.roamcity_name,a.roamcity_id,a.huadan_typename,
nvl(c1.AREATYPE,c2.AREATYPE) AREATYPE,
nvl(c1.PROVINCEID,c1.PROVINCEID) PROVINCEID,
nvl(c1.PROVINCENAME,c1.PROVINCENAME) PROVINCENAME
from shzc.lw_wzjk_zhsy_bdcd a,
(select * from shzc.lw_wzjk_zhsy_fxzb_rq b where b.排名<=30 ) b,
(select * from common.SA_DB_NATAREAINFO@bcv c where c.AREATYPE=''1'') c1,
(select * from common.SA_DB_NATAREAINFO@bcv c where c.AREATYPE=''2'') c2,
shzc.lw_wzjk_zhsy_bd_tmp_cshz t
where a.roamcity_id=c1.areaid(+)
and a.roamcity_id=c2.areaid(+)
and a.product_no=t.product_no
and a.cycle=b.cycle
and nvl(a.ROAMCITY_NAME,''0'')=''淄博'' ) a
group by a.product_no,PROVINCENAME,roamcity_name ';
EXECUTE IMMEDIATE (SQL_STRING);
----可以增加号码索引 ----建索引
SQL_STRING:='create index shzc.lw_wzjk_zb on shzc.lw_wzjk_zhsy_fxzb_zb(product_no) ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;
----根据号码使用地最多天数进行汇总 ---省排名
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_sheng'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_sheng as
select a.* from
(select a.product_no,PROVINCENAME,count(distinct a.cycle) cycles,count(distinct a.roamcity_name) roamcity_name,min(a.cycle) min_cycle,max(a.cycle) max_cycle,
row_number() over (partition by a.product_no order by count(distinct a.cycle) desc ) 排名
from
(select a.cycle,a.product_no,a.imei14,a.roamcity_name,a.roamcity_id,a.huadan_typename,
nvl(c1.AREATYPE,c2.AREATYPE) AREATYPE,
nvl(c1.PROVINCEID,c1.PROVINCEID) PROVINCEID,
nvl(c1.PROVINCENAME,c1.PROVINCENAME) PROVINCENAME
from shzc.lw_wzjk_zhsy_bdcd a,
(select * from shzc.lw_wzjk_zhsy_fxzb_rq b where b.排名<=30 ) b,
(select * from common.SA_DB_NATAREAINFO@bcv c where c.AREATYPE=''1'') c1,
(select * from common.SA_DB_NATAREAINFO@bcv c where c.AREATYPE=''2'') c2,
shzc.lw_wzjk_zhsy_bd_tmp_cshz t
where a.roamcity_id=c1.areaid(+)
and a.roamcity_id=c2.areaid(+)
and a.product_no=t.product_no
and a.cycle=b.cycle
and nvl(nvl(c1.PROVINCENAME,c1.PROVINCENAME),''0'') not in (''0'',''山东'') ) a
group by a.product_no,PROVINCENAME) a
where 排名<=3 ';
EXECUTE IMMEDIATE (SQL_STRING);
----可以增加号码索引 ----建索引
SQL_STRING:='create index shzc.lw_wzjk_sheng on shzc.lw_wzjk_zhsy_fxzb_sheng(product_no) ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;
----根据号码使用地最多天数进行汇总 ---山东
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_sd'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_sd as
select a.* from
(select a.product_no,PROVINCENAME,count(distinct a.cycle) cycles,count(distinct a.roamcity_name) roamcity_name,min(a.cycle) min_cycle,max(a.cycle) max_cycle,
row_number() over (partition by a.product_no order by count(distinct a.cycle) desc ) 排名
from
(select a.cycle,a.product_no,a.imei14,a.roamcity_name,a.roamcity_id,a.huadan_typename,
nvl(c1.AREATYPE,c2.AREATYPE) AREATYPE,
nvl(c1.PROVINCEID,c1.PROVINCEID) PROVINCEID,
nvl(c1.PROVINCENAME,c1.PROVINCENAME) PROVINCENAME
from shzc.lw_wzjk_zhsy_bdcd a,
(select * from shzc.lw_wzjk_zhsy_fxzb_rq b where b.排名<=30 ) b,
(select * from common.SA_DB_NATAREAINFO@bcv c where c.AREATYPE=''1'') c1,
(select * from common.SA_DB_NATAREAINFO@bcv c where c.AREATYPE=''2'') c2,
shzc.lw_wzjk_zhsy_bd_tmp_cshz t
where a.roamcity_id=c1.areaid(+)
and a.roamcity_id=c2.areaid(+)
and a.product_no=t.product_no
and a.cycle=b.cycle
and nvl(nvl(c1.PROVINCENAME,c1.PROVINCENAME),''0'') in (''山东'') ) a
group by a.product_no,PROVINCENAME) a
where 排名<=3 ';
EXECUTE IMMEDIATE (SQL_STRING);
----可以增加号码索引 ----建索引
SQL_STRING:='create index shzc.lw_wzjk_sd on shzc.lw_wzjk_zhsy_fxzb_sd(product_no) ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;
----排除只有淄博的,存在外地使用号码
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxa'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_mxa as
select a.*,nvl(b.漫出地市数,0) 外地使用地,nvl(b.漫出天数,0) 外地使用天数 ,nvl(case when nvl(b.是否淄博使用,0)=0 then 1 end ,0) 是否非淄博使用,
nvl(t.roamcity_name,''无'') 淄博,nvl(t.cycles,0) 淄博使用天数,t.min_cycle 淄博使用天开始,t.max_cycle 淄博使用天结束,
nvl(d.provincename,''无'') 山东,nvl(d.cycles,0) 山东使用天数,nvl(d.roamcity_name,0) 山东使用地市数, d.min_cycle 山东使用天开始,d.max_cycle 山东使用天结束,
round(nvl(d.cycles,0)/decode(nvl(a.cycle,0),0,1,cycle)*100,2) 山东使用占比,
nvl(t1.provincename,''无'') y1使用省,nvl(t1.roamcity_name,''无'') y1使用地,nvl(t1.cycles,0) y1使用天数,t1.min_cycle y1使用天开始,t1.max_cycle y1使用天结束,
round(nvl(t1.cycles,0)/decode(nvl(b.漫出天数,0),0,1,b.漫出天数)*100,2) y1使用占比,
nvl(t2.provincename,''无'') y2使用省,nvl(t2.roamcity_name,''无'') y2使用地,nvl(t2.cycles,0) y2使用天数,t2.min_cycle y2使用天开始,t2.max_cycle y2使用天结束,
round(nvl(t2.cycles,0)/decode(nvl(b.漫出天数,0),0,1,b.漫出天数)*100,2) y2使用占比,
nvl(t3.provincename,''无'') y3使用省,nvl(t3.roamcity_name,''无'') y3使用地,nvl(t3.cycles,0) y3使用天数,t3.min_cycle y3使用天开始,t3.max_cycle y3使用天结束,
round(nvl(t3.cycles,0)/decode(nvl(b.漫出天数,0),0,1,b.漫出天数)*100,2) y3使用占比,
nvl(s1.provincename,''无'') s1使用省,nvl(s1.cycles,0) s1使用天数,nvl(s1.roamcity_name,0) s1使用地市数,s1.min_cycle s1使用天开始,s1.max_cycle s1使用天结束,
round(nvl(s1.cycles,0)/decode(nvl(b.漫出天数,0),0,1,b.漫出天数)*100,2) s1使用占比,
nvl(s2.provincename,''无'') s2使用省,nvl(s2.cycles,0) s2使用天数,nvl(s2.roamcity_name,0) s2使用地市数,s2.min_cycle s2使用天开始,s2.max_cycle s2使用天结束,
round(nvl(s2.cycles,0)/decode(nvl(b.漫出天数,0),0,1,b.漫出天数)*100,2) s2使用占比
from shzc.lw_wzjk_zhsy_fxzb_mx a,
shzc.lw_wzjk_zhsy_bd_tmp_cshz b,
(select * from shzc.lw_wzjk_zhsy_fxzb_hz t where t.排名=1) t1,
(select * from shzc.lw_wzjk_zhsy_fxzb_hz t where t.排名=2) t2,
(select * from shzc.lw_wzjk_zhsy_fxzb_hz t where t.排名=3) t3,
shzc.lw_wzjk_zhsy_fxzb_zb t,
(select * from shzc.lw_wzjk_zhsy_fxzb_sheng s where s.排名=1) s1,
(select * from shzc.lw_wzjk_zhsy_fxzb_sheng s where s.排名=2) s2,
shzc.lw_wzjk_zhsy_fxzb_sd d
where a.product_no=b.product_no(+)
and a.product_no=t1.product_no(+)
and a.product_no=t2.product_no(+)
and a.product_no=t3.product_no(+)
and a.product_no=t.product_no(+)
and a.product_no=s1.product_no(+)
and a.product_no=s2.product_no(+)
and a.product_no=d.product_no(+) ';
EXECUTE IMMEDIATE (SQL_STRING);
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mx'),'SHZC');
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_hz'),'SHZC');
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_sheng'),'SHZC');
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_sd'),'SHZC');
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_zb'),'SHZC');
----可以增加号码索引 ----建索引
SQL_STRING:='create index shzc.lw_wzjk_mxa on shzc.lw_wzjk_zhsy_fxzb_mxa(product_no) ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;
---取状态
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxb'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_mxb as
select * from
(select a.product_no,b.subsid,b.acctid,b.prodid,pp.prodname,B.STATUS,zt.dictname 状态,b.statusdate 状态时间,
b.createdate 入网时间,B.REGISTERORGID,B.OWNERORGID,b.stopkey,
row_number() over (partition by a.product_no order by nvl(nvl(b.createdate,b.STAMPTIME),b.STATUSDATE) desc ) 排名
from shzc.lw_wzjk_zhsy_bd_tmp_cshz a,(select * from zhyw.subscriber b where b.status not in (''US26'') ) B ,
(select * from tbcs.dict_item@bcv where groupid=''US'') zt ,tbcs.product@bcv pp
where a.product_no=b.servnumber(+)
and zt.dictid(+)=b.status
and pp.prodid(+)=b.prodid) a
where 排名=1 ';
EXECUTE IMMEDIATE (SQL_STRING);
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_bd_tmp_cshz'),'SHZC');
----可以增加号码索引 ----建索引
SQL_STRING:='create index shzc.lw_wzjk_mxb on shzc.lw_wzjk_zhsy_fxzb_mxb(product_no) ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;
-----号码可以找到使用记录的保留
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxc'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_mxc as
select b.*,a.subsid,a.prodname,a.入网时间,a.status,a.状态,a.状态时间,a.stopkey,shc.shc_func_stopkey(a.stopkey)停机锁,a.ownerorgid
from shzc.lw_wzjk_zhsy_fxzb_mxa b,
(select * from shzc.lw_wzjk_zhsy_fxzb_mxb a where a.subsid is not null) a
where b.product_no = a.product_no ';
EXECUTE IMMEDIATE (SQL_STRING);
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxa'),'SHZC');
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxb'),'SHZC');
----可以增加号码索引 ----建索引
SQL_STRING:='create index shzc.lw_wzjk_mxc on shzc.lw_wzjk_zhsy_fxzb_mxc(product_no) ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;
----涉及号码使用量情况
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxd'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_mxd as
select a.*,
nvl(b1.mtd_in_call_counts,0) 上月主叫次数,nvl(b1.mtd_in_call_duration_m,0) 上月主叫分钟,nvl(b1.sw_call_duration_m,0) 上月省外分钟,
round(nvl(c1.ll_all,0)/1024/1024,2) 上月流量M,nvl(c1.sw_ll_m,0) 上月省外流量M,
nvl(b2.mtd_in_call_counts,0) 本月主叫次数,nvl(b2.mtd_in_call_duration_m,0) 本月主叫分钟,nvl(b2.sw_call_duration_m,0) 本月省外分钟,
round(nvl(c2.ll_all,0)/1024/1024,2) 本月流量M,nvl(c2.sw_ll_m,0) 本月省外流量M
from shzc.lw_wzjk_zhsy_fxzb_mxc a,
(select b.product_no,sum(b.mtd_in_call_counts) mtd_in_call_counts,sum(b.mtd_in_call_duration_m) mtd_in_call_duration_m,sum(b.sw_call_duration_m+b.gj_call_duration_m) sw_call_duration_m
from zibo.dw_product_call_dt_'||v_last_day||' b group by b.product_no) b1,
(select b.product_no,sum(b.mtd_in_call_counts) mtd_in_call_counts,sum(b.mtd_in_call_duration_m) mtd_in_call_duration_m,sum(b.sw_call_duration_m+b.gj_call_duration_m) sw_call_duration_m
from zibo.dw_product_call_dt_'||P_DAY||' b group by b.product_no) b2,
(select c.product_no,sum(c.ll_all) ll_all,sum(c.sw_ll_m) sw_ll_m from zibo.zb_gprs_ll_'||v_monsrq||' c group by c.product_no )c1,
(select c.product_no,sum(c.ll_all) ll_all,sum(c.sw_ll_m) sw_ll_m from zibo.zb_gprs_ll_'||v_monsr||' c group by c.product_no )c2
where a.product_no=b1.product_no(+)
and a.product_no=b2.product_no(+)
and a.product_no=c1.product_no(+)
and a.product_no=c2.product_no(+) ';
EXECUTE IMMEDIATE (SQL_STRING);
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxc'),'SHZC');
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxe'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_mxe as
select a.*,t.userid,d.CERTID,d.CERTTYPE,d.CUSTNAME,b.hd_iden_no,b.hd_cust_name,nvl(g1.prov_name,g2.prov_name) prov_name,nvl(g1.city_name,g3.city_name) city_name,g1.area_name
from shzc.lw_wzjk_zhsy_fxzb_mxd a,
zhyw.subscriber t,
tbcs.customer@bcv d,
shzc.shzc_age_jqb b,
shzc.idcard_city_crad_ok g1,
shzc.idcard_city_crad_sheng g2,
shzc.idcard_city_crad_shi g3
where a.subsid=t.subsid(+)
and t.userid=d.CUSTID(+)
and a.subsid=b.subsid(+)
and substr(d.CERTID,1,6)=g1.crad_id(+)
and substr(d.CERTID,1,2)=g2.crad_id(+)
and substr(d.CERTID,1,4)=g3.crad_id(+)';
EXECUTE IMMEDIATE (SQL_STRING);
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxd'),'SHZC');
----可以增加号码索引 ----建索引
SQL_STRING:='create index shzc.lw_wzjk_mxe on shzc.lw_wzjk_zhsy_fxzb_mxe(product_no) ';
EXECUTE IMMEDIATE (SQL_STRING);
commit;
---月明细数据存档
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mx_'||v_monsr),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_mx_'||v_monsr||' as
select * from shzc.lw_wzjk_zhsy_fxzb_mxe a ';
EXECUTE IMMEDIATE (SQL_STRING);
-----将涉及表清除,防止占用空间
--zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_bd'),'SHZC');
--zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_bd_tmp_cshz'),'SHZC');
--zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mx'),'SHZC');
--zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_hz'),'SHZC');
--zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_sheng'),'SHZC');
--zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_sd'),'SHZC');
--zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_zb'),'SHZC');
--zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxa'),'SHZC');
--zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxb'),'SHZC');
--zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxc'),'SHZC');
--zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxd'),'SHZC');
---剩余大表压缩处理
SQL_STRING:='alter table shzc.lw_wzjk_zhsy_fxzb_mxe move tablespace DS_DATA1 compress' ;
execute immediate (SQL_STRING);
SQL_STRING:='alter table shzc.lw_wzjk_zhsy_fxzb_mx_'||v_monsr||' move tablespace DS_DATA1 compress' ;
execute immediate (SQL_STRING);
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_mxf'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_mxf as
select a.PRODUCT_NO, SUBSID, PRODNAME, 入网时间, 状态, 状态时间, 停机锁, substr(OWNERORGID,1,8) qxid,b.name,
CYCLE 近30天使用天数, ROAMCITY_NAME 近30天使用地市,
是否非淄博使用, 淄博, 淄博使用天数,round(nvl(淄博使用天数,0)/decode(nvl(CYCLE,0),0,1,CYCLE)*100,2) 淄博使用占比,
山东, 山东使用天数, 山东使用占比,
外地使用天数,外地使用地,
Y1使用省, Y1使用地, Y1使用天数, Y1使用占比,
Y2使用省, Y2使用地, Y2使用天数, Y2使用占比,
Y3使用省, Y3使用地, Y3使用天数, Y3使用占比,
S1使用省, S1使用天数, S1使用占比,
S2使用省, S2使用天数, S2使用占比,
上月主叫次数, 上月主叫分钟, 上月省外分钟, 上月流量M, 上月省外流量M,
round(a.上月省外流量m/1024*1.55,2) 上月省外流量结算元,
本月主叫次数, 本月主叫分钟, 本月省外分钟, 本月流量M, 本月省外流量M,
round(a.本月省外流量m/1024*1.55,2) 本月省外流量结算元
from shzc.lw_wzjk_zhsy_fxzb_mxe a,
zhyw.yhh_slyc_priv_prod_county b
where (a.外地使用地>0 or a.上月省外流量m+a.本月省外流量m>0)
and substr(OWNERORGID,1,8)=b.county_id(+)' ;
execute immediate (SQL_STRING);
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_swyh'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_swyh as
select a.*,b.套餐档次,b.档次_jiazhi,b.上月arpu,b.上上月arpu,b.上上上月arpu,case
when a.是否非淄博使用=1 then ''长期漫游客户''
when a.淄博使用天数=a.近30天使用天数/100*10 and a.淄博使用天数=a.近30天使用天数/100*80 then ''偶发外出'' end 用户类型
from shzc.lw_wzjk_zhsy_fxzb_mxf a,
zhyw.shc_all_label_mx b
where a.近30天使用天数-a.山东使用天数>0
and a.状态=''正使用''
and a.subsid=b.subsid(+)' ;
execute immediate (SQL_STRING);
----prodid 资费类型
--create table shzc.lw_wzjk_zhsy_fxzb_swyh_yhtype
--(prodid varchar2(200),资费类型 varchar2(200) );
--select * from shzc.lw_wzjk_zhsy_fxzb_swyh_yhtype for update ;
--当前流量扩容客户数
--产品编码:PROD20210413283.999,当月在用
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_swyha'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_swyha as
select * from
(select a.subsid,a.oid,a.prodid,a.privid,a.startdate,a.enddate,a.applyoid,a.canceloid,
row_number() over (partition by a.subsid order by a.startdate desc ) 排名
from zhyw.subs_privilege a,
shzc.lw_wzjk_zhsy_fxzb_swyh b
where a.prodid=''PROD20210413283.999''
and a.subsid=b.subsid
and nvl(a.enddate,sysdate+9999)>a.startdate
and a.startdateto_date('''||v_monsr||''',''yyyymm'')) a
where 排名=1' ;
execute immediate (SQL_STRING);
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_swyhb'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_swyhb as
select * from
(select a.subsid,a.oid,a.prodid,a.privid,a.startdate,a.enddate,a.applyoid,a.canceloid,c.资费类型,
row_number() over (partition by a.subsid order by a.startdate desc ) 排名
from zhyw.subs_privilege a,
shzc.lw_wzjk_zhsy_fxzb_swyh b,
shzc.lw_wzjk_zhsy_fxzb_swyh_yhtype c
where a.prodid=c.prodid
and a.subsid=b.subsid
and nvl(a.enddate,sysdate+9999)>a.startdate
and a.startdateto_date('''||v_monsr||''',''yyyymm'')) a
where 排名=1' ;
execute immediate (SQL_STRING);
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_swyhc'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_swyhc as
select a.*,nvl(a.上上上月arpu,0)+nvl(a.上上月arpu,0)+nvl(a.上月arpu,0) arpu,
nvl(case when a.上上上月arpu is not null then 1 end,0)+
nvl(case when a.上上月arpu is not null then 1 end,0)+
nvl(case when a.上月arpu is not null then 1 end,0) 月数,
nvl(case when b.prodid is null then 0 end,1) 流量扩容,nvl(c.资费类型,''其他'') 资费类型
from shzc.lw_wzjk_zhsy_fxzb_swyh a,
shzc.lw_wzjk_zhsy_fxzb_swyha b,
shzc.lw_wzjk_zhsy_fxzb_swyhb c
where a.subsid=b.subsid(+)
and a.subsid=c.subsid(+)' ;
execute immediate (SQL_STRING);
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_swyhc'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_swyhd as
select a.*,round(a.arpu/decode(a.月数,0,1,a.月数),2) 月均arpu
from shzc.lw_wzjk_zhsy_fxzb_swyhc a' ;
execute immediate (SQL_STRING);
---每月存个明细月数据
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_sw_'||v_monsr),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_sw_'||v_monsr||' as
select * from shzc.lw_wzjk_zhsy_fxzb_swyhd' ;
execute immediate (SQL_STRING);
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_swyhe'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_swyhe as
select '''||P_DAY||''' cycle,''全部'' type,a.qxid,a.name,
count(distinct a.subsid) 客户数,
round(sum(a.上月省外流量m)/1024,2) 上月漫出流量G,
sum(a.上月省外流量结算元) 上月结出费用,
round(sum(a.本月省外流量m)/1024,2) 本月漫出流量G,
sum(a.本月省外流量结算元) 本月结算费用,
count(distinct case when a.流量扩容=1 then a.subsid end) 当前流量扩容客户数,
round(sum(nvl(a.档次_jiazhi,0))/decode(count(distinct a.subsid),0,1,count(distinct a.subsid)),2) 户均套餐档次,
round(sum(nvl(a.月均arpu,0))/decode(count(distinct a.subsid),0,1,count(distinct a.subsid)),2) 户均APRU
from shzc.lw_wzjk_zhsy_fxzb_swyhd a
group by a.qxid,a.name
union all
select '''||P_DAY||''' cycle,''全部'' type,''SD.LC'' qxid,''合计'' name,
count(distinct a.subsid) 客户数,
round(sum(a.上月省外流量m)/1024,2) 上月漫出流量G,
sum(a.上月省外流量结算元) 上月结出费用,
round(sum(a.本月省外流量m)/1024,2) 本月漫出流量G,
sum(a.本月省外流量结算元) 本月结算费用,
count(distinct case when a.流量扩容=1 then a.subsid end) 当前流量扩容客户数,
round(sum(nvl(a.档次_jiazhi,0))/decode(count(distinct a.subsid),0,1,count(distinct a.subsid)),2) 户均套餐档次,
round(sum(nvl(a.月均arpu,0))/decode(count(distinct a.subsid),0,1,count(distinct a.subsid)),2) 户均APRU
from shzc.lw_wzjk_zhsy_fxzb_swyhd a
union all
select '''||P_DAY||''' cycle,a.用户类型 type,a.qxid,a.name,
count(distinct a.subsid) 客户数,
round(sum(a.上月省外流量m)/1024,2) 上月漫出流量G,
sum(a.上月省外流量结算元) 上月结出费用,
round(sum(a.本月省外流量m)/1024,2) 本月漫出流量G,
sum(a.本月省外流量结算元) 本月结算费用,
count(distinct case when a.流量扩容=1 then a.subsid end) 当前流量扩容客户数,
round(sum(nvl(a.档次_jiazhi,0))/decode(count(distinct a.subsid),0,1,count(distinct a.subsid)),2) 户均套餐档次,
round(sum(nvl(a.月均arpu,0))/decode(count(distinct a.subsid),0,1,count(distinct a.subsid)),2) 户均APRU
from shzc.lw_wzjk_zhsy_fxzb_swyhd a
group by a.用户类型,a.qxid,a.name
union all
select '''||P_DAY||''' cycle,a.用户类型 type,''SD.LC'' qxid,''合计'' name,
count(distinct a.subsid) 客户数,
round(sum(a.上月省外流量m)/1024,2) 上月漫出流量G,
sum(a.上月省外流量结算元) 上月结出费用,
round(sum(a.本月省外流量m)/1024,2) 本月漫出流量G,
sum(a.本月省外流量结算元) 本月结算费用,
count(distinct case when a.流量扩容=1 then a.subsid end) 当前流量扩容客户数,
round(sum(nvl(a.档次_jiazhi,0))/decode(count(distinct a.subsid),0,1,count(distinct a.subsid)),2) 户均套餐档次,
round(sum(nvl(a.月均arpu,0))/decode(count(distinct a.subsid),0,1,count(distinct a.subsid)),2) 户均APRU
from shzc.lw_wzjk_zhsy_fxzb_swyhd a
group by a.用户类型' ;
execute immediate (SQL_STRING);
SQL_STRING:='delete shzc.lw_wzjk_zhsy_fxzb_swyh_qxhz where cycle='''||P_DAY||''' ' ;
execute immediate (SQL_STRING);
commit;
SQL_STRING:=' insert into shzc.lw_wzjk_zhsy_fxzb_swyh_qxhz
select * from shzc.lw_wzjk_zhsy_fxzb_swyhe a ' ;
execute immediate (SQL_STRING);
commit;
zhyw.shc_drop_retable(upper('lw_wzjk_zhsy_fxzb_swyhf'),'SHZC');
SQL_STRING:='create table shzc.lw_wzjk_zhsy_fxzb_swyhf as
select '''||P_DAY||''' cycle,a.资费类型,a.用户类型,
count(distinct a.subsid) 客户数,
round(sum(a.上月省外流量m)/1024,2) 上月漫出流量G,
sum(a.上月省外流量结算元) 上月结出费用,
round(sum(a.本月省外流量m)/1024,2) 本月漫出流量G,
sum(a.本月省外流量结算元) 本月结算费用,
count(distinct case when a.流量扩容=1 then a.subsid end) 当前流量扩容客户数,
round(sum(nvl(a.档次_jiazhi,0))/decode(count(distinct a.subsid),0,1,count(distinct a.subsid)),2) 户均套餐档次,
round(sum(nvl(a.月均arpu,0))/decode(count(distinct a.subsid),0,1,count(distinct a.subsid)),2) 户均APRU
from shzc.lw_wzjk_zhsy_fxzb_swyhd a
group by a.资费类型,a.用户类型
union all
select '''||P_DAY||''' cycle,a.资费类型,''全部''用户类型,
count(distinct a.subsid) 客户数,
round(sum(a.上月省外流量m)/1024,2) 上月漫出流量G,
sum(a.上月省外流量结算元) 上月结出费用,
round(sum(a.本月省外流量m)/1024,2) 本月漫出流量G,
sum(a.本月省外流量结算元) 本月结算费用,
count(distinct case when a.流量扩容=1 then a.subsid end) 当前流量扩容客户数,
round(sum(nvl(a.档次_jiazhi,0))/decode(count(distinct a.subsid),0,1,count(distinct a.subsid)),2) 户均套餐档次,
round(sum(nvl(a.月均arpu,0))/decode(count(distinct a.subsid),0,1,count(distinct a.subsid)),2) 户均APRU
from shzc.lw_wzjk_zhsy_fxzb_swyhd a
group by a.资费类型 ' ;
execute immediate (SQL_STRING);
SQL_STRING:='delete shzc.lw_wzjk_zhsy_fxzb_swyh_zyhz where cycle='''||P_DAY||''' ' ;
execute immediate (SQL_STRING);
commit;
SQL_STRING:=' insert into shzc.lw_wzjk_zhsy_fxzb_swyh_zyhz
select * from shzc.lw_wzjk_zhsy_fxzb_swyhf a ' ;
execute immediate (SQL_STRING);
commit;