当前位置:网站首页>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;
边栏推荐
- Jatpack------LiveData
- 高并发介绍及应对
- Qt QScrollArea
- MySQL查询附近的数据.并按距离进行排序.
- [chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?
- 20220527_数据库过程_语句留档
- mysql重置密码,忘记密码,重置root密码,重置mysql密码
- [chestnut sugar GIS] ArcScene - how to make elevation map with height
- Construction of Hisilicon 3559 universal platform: draw a frame on the captured YUV image
- Dahua cloud native load balancing article - the passenger flow of small restaurants has increased
猜你喜欢
![P7072 [csp-j2020] live broadcast Award](/img/bc/fcbc2b1b9595a3bd31d8577aba9b8b.png)
P7072 [csp-j2020] live broadcast Award

The first batch of Tencent cloud completed the first cloud native security maturity assessment in China

悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖

Qt QScrollArea

Qt QSplitter拆分器
![[LeetCode] 多数元素【169】](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[LeetCode] 多数元素【169】

xshell配置xforward转发火狐浏览器

Performance optimization - rigorous mode
![[Solved] Splunk: Cannot get username when all users are selected“](/img/13/1e824c8005701e21fc5b4e73308d53.png)
[Solved] Splunk: Cannot get username when all users are selected“

位的高阶运算
随机推荐
Freshman learning sharing
PMP project integration management
2016. 增量元素之间的最大差值
【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
情感对话识别与生成简述
分布式监控系统zabbix
pytorch训练CPU占用持续增长(bug)
Learning records of data analysis (II) -- simple use of response surface method and design expert
Go语言sqlx库操作SQLite3数据库增删改查
用sentinel熔断比例阈值改不了,设置慢调用比例没效果
数据标注典型案例,景联文科技如何助力企业搭建数据方案
go 多线程数据搜索
The first batch of Tencent cloud completed the first cloud native security maturity assessment in China
20220527_数据库过程_语句留档
LeetCode 968. Monitor binary tree
Stop slave is stuck -- the event of the transaction is not copied completely
Uniapp wechat login returns user name and Avatar
景联文科技低价策略帮助AI企业降低模型训练成本
手写ORM(对象关系映射)增删改查
[Solved] Splunk: Cannot get username when all users are selected“