当前位置:网站首页>20220524_数据库过程_语句留档
20220524_数据库过程_语句留档
2022-07-02 22:09:00 【szc_1985】
单日外呼号码超过10个,同时外呼号码离散度大于0.8,并且外呼的号码与近10天内外呼号码不重叠。
需要字段:号码、主叫通话次数、主叫离散度、号码重叠率
use zibo_oracle_new;
drop table if EXISTS lw_yyth_hmlsd_ycjk_hzjg;
create table lw_yyth_hmlsd_ycjk_hzjg(
cycle_time varchar2(8),PRODUCT_NO varchar2(20), min_TIME datetime, max_TIME datetime, ROAMCITYs decimal(21), CELL_IDs decimal(21),
IMEIs decimal(21), OPP_CITYs decimal(21), th_cs_zong decimal(21), th_hm_zong decimal(21),
zj_cs_zong decimal(21),zj_hm_zong decimal(21), zj_lsd decimal(26,2), OPPOSITE_NOs decimal(21),
OPPOSITE_NO_q decimal(21)
)engine=oracle.zibo_new;
#登录 zibo
use zibo;
#一个号码主叫通话次数大于等于 10次,外呼号码离散度0.8及以上 #详单数据生成
drop table if EXISTS lw_yyth_hmlsd_ycjk_mx;
create table lw_yyth_hmlsd_ycjk_mx as
select USER_ID,PRODUCT_NO,CALLTYPE_ID,OPPOSITE_NO,THIRDTELNUM,CALL_DURATION,CALL_DURATION_M,
START_DATETIME,ROAMCITY_ID,OPP_CITY_ID,OPPOSITE_ROAMCITY_ID,LAC_ID,CELL_ID,‘语音’ huadan_typename,IMEI
from zibo.cdr_call_${dayid} a ;
#按号码汇总 ,筛选情况
drop table if EXISTS lw_yyth_hmlsd_ycjk_hz;
create table lw_yyth_hmlsd_ycjk_hz as
select a.PRODUCT_NO,
min(START_DATETIME) min_TIME,
max(START_DATETIME) max_TIME,
count(distinct ROAMCITY_ID) ROAMCITYs,
count(distinct CELL_ID) CELL_IDs,
count(distinct IMEI) IMEIs,
count(distinct OPP_CITY_ID) OPP_CITYs,
count(a.OPPOSITE_NO) th_cs_zong,
count(distinct a.OPPOSITE_NO) th_hm_zong,
sum(CALL_DURATION_M) CALL_DURATION_M,
count(case when CALLTYPE_ID=‘1’ then a.OPPOSITE_NO end) zj_cs_zong,
count(distinct case when CALLTYPE_ID=‘1’ then a.OPPOSITE_NO end) zj_hm_zong,
sum(nvl(case when CALLTYPE_ID=‘1’ then a.CALL_DURATION_M end,0)) zj_DURATION_M,
round(count( distinct case when CALLTYPE_ID=‘1’ then a.OPPOSITE_NO end)/
count( case when CALLTYPE_ID=‘1’ then a.OPPOSITE_NO end)*100,2) zj_lsd
from lw_yyth_hmlsd_ycjk_mx a
group by a.PRODUCT_NO
having count( case when CALLTYPE_ID=‘1’ then a.OPPOSITE_NO end) >=10;
drop table if EXISTS lw_yyth_hmlsd_ycjk_hza;
create table lw_yyth_hmlsd_ycjk_hza as
select * from lw_yyth_hmlsd_ycjk_hz a where a.zj_lsd>=80;
#符合条号码话单明细
drop table if EXISTS lw_yyth_hmlsd_ycjk_mxs;
create table lw_yyth_hmlsd_ycjk_mxs as
select PRODUCT_NO,OPPOSITE_NO,count(OPPOSITE_NO) count_cs,sum(CALL_DURATION_M) CALL_DURATION_M from lw_yyth_hmlsd_ycjk_mx a
where exists (select 1 from lw_yyth_hmlsd_ycjk_hza t where a.PRODUCT_NO=t.PRODUCT_NO)
and CALLTYPE_ID=‘1’
group by PRODUCT_NO,OPPOSITE_NO;
近10天这些号码的通话情况
drop table if EXISTS lw_yyth_hmlsd_ycjk_qjtmx;
create table lw_yyth_hmlsd_ycjk_qjtmx as
前1天
select PRODUCT_NO,START_DATETIME,ROAMCITY_ID,LAC_ID,CELL_ID ,‘语音’ huadan_typename,IMEI,OPPOSITE_NO,CALLTYPE_ID
from zibo.cdr_call_${pdayid} a where exists (select 1 from lw_yyth_hmlsd_ycjk_hza t where a.PRODUCT_NO=t.PRODUCT_NO) and CALLTYPE_ID =‘1’
union all
前2天
select PRODUCT_NO,START_DATETIME,ROAMCITY_ID,LAC_ID,CELL_ID ,‘语音’,IMEI ,OPPOSITE_NO,CALLTYPE_ID
from zibo.cdr_call_${p2dayid} a where exists (select 1 from lw_yyth_hmlsd_ycjk_hza t where a.PRODUCT_NO=t.PRODUCT_NO) and CALLTYPE_ID =‘1’
union all
前3天
select PRODUCT_NO,START_DATETIME,ROAMCITY_ID,LAC_ID,CELL_ID ,‘语音’,IMEI ,OPPOSITE_NO,CALLTYPE_ID
from zibo.cdr_call_${p3dayid} a where exists (select 1 from lw_yyth_hmlsd_ycjk_hza t where a.PRODUCT_NO=t.PRODUCT_NO) and CALLTYPE_ID =‘1’
union all
前4天
select PRODUCT_NO,START_DATETIME,ROAMCITY_ID,LAC_ID,CELL_ID ,‘语音’,IMEI ,OPPOSITE_NO,CALLTYPE_ID
from zibo.cdr_call_${p4dayid} a where exists (select 1 from lw_yyth_hmlsd_ycjk_hza t where a.PRODUCT_NO=t.PRODUCT_NO) and CALLTYPE_ID =‘1’
union all
前5天
select PRODUCT_NO,START_DATETIME,ROAMCITY_ID,LAC_ID,CELL_ID ,‘语音’,IMEI ,OPPOSITE_NO,CALLTYPE_ID
from zibo.cdr_call_${p5dayid} a where exists (select 1 from lw_yyth_hmlsd_ycjk_hza t where a.PRODUCT_NO=t.PRODUCT_NO) and CALLTYPE_ID =‘1’
union all
前6天
select PRODUCT_NO,START_DATETIME,ROAMCITY_ID,LAC_ID,CELL_ID ,‘语音’,IMEI ,OPPOSITE_NO,CALLTYPE_ID
from zibo.cdr_call_${p6dayid} a where exists (select 1 from lw_yyth_hmlsd_ycjk_hza t where a.PRODUCT_NO=t.PRODUCT_NO) and CALLTYPE_ID =‘1’
union all
前7天
select PRODUCT_NO,START_DATETIME,ROAMCITY_ID,LAC_ID,CELL_ID ,‘语音’,IMEI ,OPPOSITE_NO,CALLTYPE_ID
from zibo.cdr_call_${p7dayid} a where exists (select 1 from lw_yyth_hmlsd_ycjk_hza t where a.PRODUCT_NO=t.PRODUCT_NO) and CALLTYPE_ID =‘1’
union all
前8天
select PRODUCT_NO,START_DATETIME,ROAMCITY_ID,LAC_ID,CELL_ID ,‘语音’,IMEI ,OPPOSITE_NO,CALLTYPE_ID
from zibo.cdr_call_${p8dayid} a where exists (select 1 from lw_yyth_hmlsd_ycjk_hza t where a.PRODUCT_NO=t.PRODUCT_NO) and CALLTYPE_ID =‘1’
;
drop table if EXISTS lw_yyth_hmlsd_ycjk_qjthz;
create table lw_yyth_hmlsd_ycjk_qjthz as
select a.PRODUCT_NO,a.OPPOSITE_NO,count( distinct substr(START_DATETIME,1,10)) count_day,count(a.OPPOSITE_NO) count_cs
from lw_yyth_hmlsd_ycjk_qjtmx a
group by a.PRODUCT_NO,a.OPPOSITE_NO;
号码数据整合
drop table if EXISTS lw_yyth_hmlsd_ycjk_hmhzzl;
create table lw_yyth_hmlsd_ycjk_hmhzzl as
select t1.PRODUCT_NO,t1.OPPOSITE_NO,t1.count_cs,t1.CALL_DURATION_M,t2.count_day,t2.count_cs qt_count_cs
from lw_yyth_hmlsd_ycjk_mxs t1
left join lw_yyth_hmlsd_ycjk_qjthz t2
on t1.PRODUCT_NO=t2.PRODUCT_NO
and t1.OPPOSITE_NO=t2.OPPOSITE_NO ;
drop table if EXISTS lw_yyth_hmlsd_ycjk_hmhzzla;
create table lw_yyth_hmlsd_ycjk_hmhzzla as
select a.PRODUCT_NO,count( distinct a.OPPOSITE_NO) OPPOSITE_NOs,
count( distinct case when qt_count_cs is not null then a.OPPOSITE_NO end ) OPPOSITE_NO_q
from lw_yyth_hmlsd_ycjk_hmhzzl a
group by a.PRODUCT_NO;
导出结果
drop table if EXISTS lw_yyth_hmlsd_ycjk_hzjg;
create table lw_yyth_hmlsd_ycjk_hzjg as
select ${dayid} cycle,a.*,b.OPPOSITE_NOs,b.OPPOSITE_NO_q
from lw_yyth_hmlsd_ycjk_hza a,
lw_yyth_hmlsd_ycjk_hmhzzla b
where a.PRODUCT_NO=b.PRODUCT_NO;
导入数据
insert into zibo_oracle_new.lw_yyth_hmlsd_ycjk_hzjg
select cycle ,PRODUCT_NO,min_TIME,max_TIME,ROAMCITYs,CELL_IDs ,
IMEIs ,OPP_CITYs,th_cs_zong,th_hm_zong ,
zj_cs_zong , zj_hm_zong , zj_lsd , OPPOSITE_NOs , OPPOSITE_NO_q
from lw_yyth_hmlsd_ycjk_hzjg ;
#另一个数据平台
SQL_STRING:=’ insert into shzc.lw_yyth_hmlsd_ycjk_hzbd
select a.cycle_time 日期,
a.product_no 号码,
a.min_time 通话最早时间,
a.max_time 通话最后时间,
b.start_datetime 最后时间,
b.roamcity_name 最后使用地市,
b.huadan_typename 最后类型,
b.county_id 最后区县,
b.bts_name 最后基站,
ROAMCITYS 漫游地市数,
CELL_IDS 使用基站数,
IMEIS 使用串号数,
OPP_CITYS 对方地市数,
a.th_cs_zong 日通话次数,
a.th_hm_zong 日通话号码数,
a.zj_cs_zong 日主叫次数,
a.zj_hm_zong 日主叫号码数,
a.zj_lsd 日主叫离散度,
a.opposite_no_q 号码重叠数,
round(a.opposite_no_q/a.opposite_nos*100,2) 号码重叠率
from zibo.lw_yyth_hmlsd_ycjk_hzjg a ,
zibo.lw_sasz_xdjl_zhsy_bd b
where --a.opposite_no_q/a.opposite_nos>=0.8
–and
a.product_no=b.product_no(+) ’ ;
execute immediate (SQL_STRING);
commit;
-----预警近4天异常情况,并且将15天之前数据清除,减少数据存储压力
fan_drop_retable(upper('lw_yyth_hmlsd_ycjk_daypm'),'SHZC');
SQL_STRING:='create table shzc.lw_yyth_hmlsd_ycjk_daypm as
select a.日期,row_number() over (partition by 1 order by a.日期 desc ) 排名
from shzc.lw_yyth_hmlsd_ycjk_hzbd a
group by a.日期 ' ;
execute immediate (SQL_STRING);
--数据清除
SQL_STRING:='delete from shzc.lw_yyth_hmlsd_ycjk_hzbd a
where exists (select 1 from shzc.lw_yyth_hmlsd_ycjk_daypm b where b.排名>15 and a.日期=b.日期) ' ;
execute immediate (SQL_STRING);
commit;
fan_drop_retable(upper('lw_yyth_hmlsd_ycjk_fzmxa'),'SHZC');
SQL_STRING:='create table shzc.lw_yyth_hmlsd_ycjk_fzmxa as
select a.*,b.排名 from shzc.lw_yyth_hmlsd_ycjk_hzbd a,
shzc.lw_yyth_hmlsd_ycjk_daypm b
where a.号码 in (
select a.号码 from shzc.lw_yyth_hmlsd_ycjk_hzbd a
where exists (select 1 from shzc.lw_yyth_hmlsd_ycjk_daypm b where b.排名<5 and a.日期=b.日期)
group by a.号码
having count(*)>3)
and a.日期=b.日期
and exists (select 1 from shzc.lw_yyth_hmlsd_ycjk_daypm b where b.排名<5 and a.日期=b.日期)' ;
execute immediate (SQL_STRING);
fan_drop_retable(upper('lw_yyth_hmlsd_ycjk_fzmxb'),'SHZC');
SQL_STRING:='create table shzc.lw_yyth_hmlsd_ycjk_fzmxb as
select a.号码,max(a.日期) 日期,
max(nvl(case when a.排名=4 then a.使用基站数 end,0)) y4使用基站,
max(nvl(case when a.排名=4 then a.对方地市数 end,0)) y4对方地市,
max(nvl(case when a.排名=4 then a.日主叫次数 end,0)) y4日主叫次数,
max(nvl(case when a.排名=4 then a.日主叫离散度 end,0)) y4日主叫离散度,
max(nvl(case when a.排名=4 then a.号码重叠率 end,0)) y4号码重叠率,
max(nvl(case when a.排名=3 then a.使用基站数 end,0)) y3使用基站,
max(nvl(case when a.排名=3 then a.对方地市数 end,0)) y3对方地市,
max(nvl(case when a.排名=3 then a.日主叫次数 end,0)) y3日主叫次数,
max(nvl(case when a.排名=3 then a.日主叫离散度 end,0)) y3日主叫离散度,
max(nvl(case when a.排名=3 then a.号码重叠率 end,0)) y3号码重叠率,
max(nvl(case when a.排名=2 then a.使用基站数 end,0)) y2使用基站,
max(nvl(case when a.排名=2 then a.对方地市数 end,0)) y2对方地市,
max(nvl(case when a.排名=2 then a.日主叫次数 end,0)) y2日主叫次数,
max(nvl(case when a.排名=2 then a.日主叫离散度 end,0)) y2日主叫离散度,
max(nvl(case when a.排名=2 then a.号码重叠率 end,0)) y2号码重叠率,
max(nvl(case when a.排名=1 then a.使用基站数 end,0)) y1使用基站,
max(nvl(case when a.排名=1 then a.对方地市数 end,0)) y1对方地市,
max(nvl(case when a.排名=1 then a.日主叫次数 end,0)) y1日主叫次数,
max(nvl(case when a.排名=1 then a.日主叫离散度 end,0)) y1日主叫离散度,
max(nvl(case when a.排名=1 then a.号码重叠率 end,0)) y1号码重叠率
from shzc.lw_yyth_hmlsd_ycjk_fzmxa a
where A.号码重叠率<=20
and a.使用基站数<10
group by a.号码
having count(distinct a.日期)=4' ;
execute immediate (SQL_STRING);
fan_drop_retable(upper('lw_yyth_hmlsd_ycjk_fzmxc'),'SHZC');
SQL_STRING:='create table shzc.lw_yyth_hmlsd_ycjk_fzmxc as
select a.* from
(select a.号码,b.servnumber hm,b.subsid,b.acctid,b.prodid,pp.prodname,B.STATUS,zt.dictname 状态,b.statusdate 状态时间,
b.createdate 入网时间,b.settleday 账期日,B.ENUM,B.IMSI,B.REGISTERORGID,B.OWNERORGID,
row_number() over (partition by a.号码 order by nvl(b.createdate,sysdate-9999) desc ) 排名
from shzc.lw_yyth_hmlsd_ycjk_fzmxb a,(select * from zhyw.subscriber b where b.status not in (''US26'',''US28'') /*and b.active=1*/ ) B ,
(select * from [email protected] where groupid=''US'') zt ,[email protected] pp
where a.号码=b.servnumber(+)
and zt.dictid(+)=b.status
and pp.prodid(+)=b.prodid) a
where 排名=1' ;
execute immediate (SQL_STRING);
SQL_STRING:='delete from shzc.lw_yyth_hmlsd_ycjk_fzmx_bd a where 日期='''||P_DAY||''' ' ;
execute immediate (SQL_STRING);
commit;
SQL_STRING:=' insert into shzc.lw_yyth_hmlsd_ycjk_fzmx_bd
select a.日期,
a.号码,
b.subsid,
b.入网时间,
b.registerorgid,
e.orgname,
a.y4使用基站,
a.y4对方地市,
a.y4日主叫次数,
a.y4日主叫离散度,
a.y4号码重叠率,
a.y3使用基站,
a.y3对方地市,
a.y3日主叫次数,
a.y3日主叫离散度,
a.y3号码重叠率,
a.y2使用基站,
a.y2对方地市,
a.y2日主叫次数,
a.y2日主叫离散度,
a.y2号码重叠率,
a.y1使用基站,
a.y1对方地市,
a.y1日主叫次数,
a.y1日主叫离散度,
a.y1号码重叠率
from shzc.lw_yyth_hmlsd_ycjk_fzmxb a,
shzc.lw_yyth_hmlsd_ycjk_fzmxc b,
[email protected] e
where a.号码=b.号码
and b.registerorgid=e.orgid(+) ' ;
execute immediate (SQL_STRING);
commit;
边栏推荐
- 【板栗糖GIS】arcscene—如何做出有高度的高程图
- Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月1日08:43:06
- AES高级加密协议的动机阐述
- Jatpack------LiveData
- 数据标注典型案例,景联文科技如何助力企业搭建数据方案
- Qt QProgressBar详解
- 创新实力再获认可!腾讯安全MSS获2022年度云原生安全守护先锋
- Go condition variable
- Golang interview finishing three resumes how to write
- P7072 [csp-j2020] live broadcast Award
猜你喜欢
Chow-Liu Tree
地方经销商玩转社区团购模式,百万运营分享
Boot actuator - Prometheus use
boot actuator - prometheus使用
Data analysis learning records -- complete a simple one-way ANOVA with Excel
成功改变splunk 默认URL root path
P7072 [csp-j2020] live broadcast Award
归并排序详解及应用
[羊城杯2020]easyphp
Webrtc audio and video capture and playback examples and mediastream media stream analysis
随机推荐
Jerry's fast touch does not respond [chapter]
Construction of Hisilicon 3559 universal platform: draw a frame on the captured YUV image
Chow-Liu Tree
用sentinel熔断比例阈值改不了,设置慢调用比例没效果
To myself who is about to work
Jatpack------LiveData
數據分析學習記錄--用EXCEL完成簡單的單因素方差分析
Analyse des données dossiers d'apprentissage - - analyse simple de la variance à facteur unique avec Excel
STM32串口DAM接收253字节就死机原因排查
Splunk audit setting
Array advanced improvement
高并发介绍及应对
`Usage of ${}`
[LeetCode] 反转字符串【344】
[chestnut sugar GIS] ArcScene - how to make elevation map with height
Data analysis learning records -- complete a simple one-way ANOVA with Excel
JS syntax ES6, ES7, es8, es9, ES10, es11, ES12 new features (Abstract)
Golang面试整理 三 简历如何书写
成功改变splunk 默认URL root path
Go语言sqlx库操作SQLite3数据库增删改查