a_pm_4g_poor_cell_day.sql 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. CREATE OR REPLACE FUNCTION app_screen.a_pm_4g_poor_cell_day(vi_date character varying)
  2. RETURNS text
  3. LANGUAGE plpgsql
  4. AS $function$
  5. DECLARE
  6. v_date timestamp;
  7. v_next_day timestamp;
  8. v_befor_day timestamp;
  9. v_befor1_day timestamp;
  10. v_befor2_day timestamp;
  11. v_befor3_day timestamp;
  12. v_befor4_day timestamp;
  13. v_befor5_day timestamp;
  14. v_befor_day_s varchar;
  15. v_befor1_day_s varchar;
  16. v_befor2_day_s varchar;
  17. v_befor3_day_s varchar;
  18. v_befor4_day_s varchar;
  19. v_befor5_day_s varchar;
  20. v_begin_time timestamp;
  21. v_sql text;
  22. BEGIN
  23. v_date := vi_date::timestamp;
  24. v_next_day := vi_date::timestamp + '1 day'::interval;
  25. v_befor_day := vi_date::timestamp + '-1 day'::interval;
  26. v_befor1_day := vi_date::timestamp + '-2 day'::interval;
  27. v_befor2_day := vi_date::timestamp + '-3 day'::interval;
  28. v_befor3_day := vi_date::timestamp + '-4 day'::interval;
  29. v_befor4_day := vi_date::timestamp + '-5 day'::interval;
  30. v_befor5_day := vi_date::timestamp + '-6 day'::interval;
  31. v_befor_day_s := replace(date(vi_date::timestamp + '-1 day'::interval)::varchar,'-','');
  32. v_befor1_day_s := replace(date(vi_date::timestamp + '-2 day'::interval)::varchar,'-','');
  33. v_befor2_day_s := replace(date(vi_date::timestamp + '-3 day'::interval)::varchar,'-','');
  34. v_befor3_day_s := replace(date(vi_date::timestamp + '-4 day'::interval)::varchar,'-','');
  35. v_befor4_day_s := replace(date(vi_date::timestamp + '-5 day'::interval)::varchar,'-','');
  36. v_befor5_day_s := replace(date(vi_date::timestamp + '-6 day'::interval)::varchar,'-','');
  37. v_begin_time := clock_timestamp();
  38. /*
  39. *
  40. *
  41. *联通部分共建共享统计
  42. *
  43. *
  44. *
  45. */
  46. -- 取联通区县信息
  47. v_sql := 'drop table if exists a_pm_4g_poor_cell_day_tmp01';
  48. execute v_sql;
  49. v_sql := 'create temporary table a_pm_4g_poor_cell_day_tmp01
  50. (
  51. city varchar
  52. ,county varchar
  53. ,vendor varchar
  54. ,eci varchar
  55. ,cell_name varchar
  56. )';
  57. execute v_sql;
  58. v_sql := 'insert into a_pm_4g_poor_cell_day_tmp01
  59. select
  60. a.city
  61. ,a.county
  62. ,b.vendor
  63. ,b.eci
  64. ,b.cellname
  65. from app_screen.county a
  66. left join pm_parse.per_cfg_cell b
  67. on a.city = replace(b.city,''市'','''') and a.county = b.quxian';
  68. execute v_sql;
  69. v_sql := 'drop table if exists a_pm_4g_poor_cell_day_tmp02';
  70. execute v_sql;
  71. v_sql := 'create temporary table a_pm_4g_poor_cell_day_tmp02
  72. (
  73. city varchar
  74. ,county varchar
  75. ,eci varchar
  76. ,conn_suc_poor integer
  77. ,lte_highdrop_poor integer
  78. ,ho_out_suc_poor integer
  79. ,volte_join_poor integer
  80. ,volte_highdrop_poor integer
  81. ,ul_pdcp_package_drop_poor integer
  82. ,dl_pdcp_package_drop_poor integer
  83. )';
  84. execute v_sql;
  85. v_sql := 'insert into a_pm_4g_poor_cell_day_tmp02
  86. (
  87. city
  88. ,county
  89. ,eci
  90. ,conn_suc_poor
  91. ,lte_highdrop_poor
  92. ,ho_out_suc_poor
  93. ,volte_join_poor
  94. ,volte_highdrop_poor
  95. ,ul_pdcp_package_drop_poor
  96. ,dl_pdcp_package_drop_poor
  97. )
  98. select
  99. a.city
  100. ,a.county
  101. ,a.eci
  102. ,count(distinct case when radio_conn_suc_r <= 0.9 and rrc_suc > 1000 then sdate end) conn_suc_poor
  103. ,count(distinct case when lte_drop_r >= 2 and lte_drop > 1000 then sdate end) lte_highdrop_poor
  104. ,count(distinct case when ho_out_suc_r <= 0.9 and (s1_ho_out_req+x2_ho_out_req) > 500 then sdate end) ho_out_suc_poor
  105. ,count(distinct case when erab_suc_r_qci1 < 0.98 or erab_suc_r_qci5 < 0.98 then sdate end) volte_join_poor
  106. ,count(distinct case when lte_drop_r_qci1 > 0.01 then sdate end) volte_highdrop_poor
  107. ,count(distinct case when ul_pdcp_package_drop_ratio_qci1 > 0.01 then sdate end) ul_pdcp_package_drop_poor
  108. ,count(distinct case when dl_pdcp_package_drop_ratio_qci1 > 0.01 then sdate end) dl_pdcp_package_drop_poor
  109. from a_pm_4g_poor_cell_day_tmp01 a
  110. join pm_parse.pm_4g_day b
  111. on b.sdate >= '''|| v_date ||'''::timestamp - ''6 day''::interval and b.sdate < '''|| v_date ||'''::timestamp + ''1 day''::interval
  112. and b.isp = ''联通'' and b.share = ''是''
  113. and a.eci = b.eci
  114. group by a.city,a.county,a.eci';
  115. execute v_sql;
  116. v_sql := 'drop table if exists busy_info';
  117. execute v_sql;
  118. v_sql := 'create temporary table busy_info
  119. (
  120. sdate timestamp
  121. ,eci varchar
  122. ,total_tra_mb numeric
  123. )';
  124. execute v_sql;
  125. v_sql := 'insert into busy_info
  126. select
  127. date(sdate),eci,max(total_tra_mb)
  128. from pm_parse.pm_4g_hour b
  129. where b.sdate >= '''|| v_date ||'''::timestamp - ''6 day''::interval and b.sdate < '''|| v_date ||'''::timestamp + ''1 day''::interval
  130. and b.isp = ''联通'' and b.share = ''是''
  131. group by date(sdate),eci';
  132. execute v_sql;
  133. v_sql := 'drop table if exists a_pm_4g_poor_cell_day_tmp03';
  134. execute v_sql;
  135. v_sql := 'create temporary table a_pm_4g_poor_cell_day_tmp03
  136. (
  137. eci varchar
  138. ,cqi_poor integer
  139. ,highload_prb integer
  140. ,low_speed_mbps integer
  141. )';
  142. execute v_sql;
  143. v_sql := 'insert into a_pm_4g_poor_cell_day_tmp03
  144. (
  145. eci
  146. ,cqi_poor
  147. ,highload_prb
  148. ,low_speed_mbps
  149. )
  150. select
  151. eci
  152. ,case when sum(cqi_ge7)/7 > 0.2 then 1 else 0 end
  153. ,case when avg(dl_prb_utilization) > 0.65 then 1 else 0 end
  154. ,case when avg(dl_speed_mbps) < 5 then 1 else 0 end
  155. from (
  156. select
  157. t.sdate
  158. ,t.eci
  159. ,1-t.cqi_ge7 cqi_ge7
  160. ,t.dl_prb_utilization
  161. ,dl_speed_mbps
  162. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  163. from pm_parse.pm_4g_hour_'|| v_befor5_day_s ||' t
  164. join busy_info a
  165. on a.sdate = '''|| v_befor5_day ||'''
  166. and t.eci = a.eci
  167. and t.total_tra_mb = a.total_tra_mb
  168. and t.isp = ''联通'' and t.share = ''是''
  169. union all
  170. select
  171. t.sdate
  172. ,t.eci
  173. ,1-t.cqi_ge7
  174. ,t.dl_prb_utilization
  175. ,dl_speed_mbps
  176. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  177. from pm_parse.pm_4g_hour_'|| v_befor4_day_s ||' t
  178. join busy_info a
  179. on a.sdate = '''|| v_befor4_day ||'''
  180. and t.eci = a.eci
  181. and t.total_tra_mb = a.total_tra_mb
  182. and t.isp = ''联通'' and t.share = ''是''
  183. union all
  184. select
  185. t.sdate
  186. ,t.eci
  187. ,1-t.cqi_ge7
  188. ,t.dl_prb_utilization
  189. ,dl_speed_mbps
  190. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  191. from pm_parse.pm_4g_hour_'|| v_befor3_day_s ||' t
  192. join busy_info a
  193. on a.sdate = '''|| v_befor3_day ||'''
  194. and t.eci = a.eci
  195. and t.total_tra_mb = a.total_tra_mb
  196. and t.isp = ''联通'' and t.share = ''是''
  197. union all
  198. select
  199. t.sdate
  200. ,t.eci
  201. ,1-t.cqi_ge7
  202. ,t.dl_prb_utilization
  203. ,dl_speed_mbps
  204. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  205. from pm_parse.pm_4g_hour_'|| v_befor2_day_s ||' t
  206. join busy_info a
  207. on a.sdate = '''|| v_befor2_day ||'''
  208. and t.eci = a.eci
  209. and t.total_tra_mb = a.total_tra_mb
  210. and t.isp = ''联通'' and t.share = ''是''
  211. union all
  212. select
  213. t.sdate
  214. ,t.eci
  215. ,1-t.cqi_ge7
  216. ,t.dl_prb_utilization
  217. ,dl_speed_mbps
  218. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  219. from pm_parse.pm_4g_hour_'|| v_befor1_day_s ||' t
  220. join busy_info a
  221. on a.sdate = '''|| v_befor1_day ||'''
  222. and t.eci = a.eci
  223. and t.total_tra_mb = a.total_tra_mb
  224. and t.isp = ''联通'' and t.share = ''是''
  225. union all
  226. select
  227. t.sdate
  228. ,t.eci
  229. ,1-t.cqi_ge7
  230. ,t.dl_prb_utilization
  231. ,dl_speed_mbps
  232. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  233. from pm_parse.pm_4g_hour_'|| v_befor_day_s ||' t
  234. join busy_info a
  235. on a.sdate = '''|| v_befor_day ||'''
  236. and t.eci = a.eci
  237. and t.total_tra_mb = a.total_tra_mb
  238. and t.isp = ''联通'' and t.share = ''是''
  239. union all
  240. select
  241. t.sdate
  242. ,t.eci
  243. ,1-t.cqi_ge7
  244. ,t.dl_prb_utilization
  245. ,dl_speed_mbps
  246. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  247. from pm_parse.pm_4g_hour_'|| vi_date ||' t
  248. join busy_info a
  249. on a.sdate = '''|| v_date ||'''
  250. and t.eci = a.eci
  251. and t.total_tra_mb = a.total_tra_mb
  252. and t.isp = ''联通'' and t.share = ''是''
  253. ) tb
  254. where tb.rn = 1
  255. group by eci';
  256. execute v_sql;
  257. --删除当期数据
  258. v_sql := 'delete from app_screen.a_pm_4g_poor_cell_day where sdate = '''|| v_date ||'''';
  259. execute v_sql;
  260. -- 插入目标数据
  261. v_sql := 'insert into app_screen.a_pm_4g_poor_cell_day
  262. (
  263. sdate
  264. ,city
  265. ,county
  266. ,operators
  267. ,share_cell_num
  268. ,conn_suc_poor
  269. ,lte_highdrop_poor
  270. ,cqi_poor
  271. ,low_speed_mbps
  272. ,ho_out_suc_poor
  273. ,volte_join_poor
  274. ,volte_highdrop_poor
  275. ,ul_pdcp_package_drop_poor
  276. ,dl_pdcp_package_drop_poor
  277. ,highload_prb
  278. ,poor_cell_num
  279. ,poor_cell_ratio
  280. )
  281. select
  282. '''|| v_date ||''' sdate
  283. ,coalesce(a.city,''合计'')
  284. ,coalesce(a.county,''合计'')
  285. ,''联通'' operators
  286. ,count(distinct b.eci) share_cell_num
  287. ,sum(case when b.conn_suc_poor >= 3 then 1 else 0 end)
  288. ,sum(case when b.lte_highdrop_poor >= 3 then 1 else 0 end)
  289. ,sum(c.cqi_poor)
  290. ,sum(c.low_speed_mbps)
  291. ,sum(case when b.ho_out_suc_poor >= 3 then 1 else 0 end)
  292. ,sum(case when b.volte_join_poor >= 3 then 1 else 0 end)
  293. ,sum(case when b.volte_highdrop_poor >= 3 then 1 else 0 end)
  294. ,sum(case when b.ul_pdcp_package_drop_poor >= 3 then 1 else 0 end)
  295. ,sum(case when b.dl_pdcp_package_drop_poor >= 3 then 1 else 0 end)
  296. ,sum(c.highload_prb)
  297. ,count(distinct case when b.conn_suc_poor >= 3 or b.lte_highdrop_poor >= 3 or b.ho_out_suc_poor >= 3 or b.volte_join_poor >= 3
  298. or b.volte_highdrop_poor >= 3 or b.ul_pdcp_package_drop_poor >= 3 or b.dl_pdcp_package_drop_poor >= 3
  299. or c.cqi_poor = 1 or c.low_speed_mbps = 1 then b.eci end) poor_cell_num
  300. ,count(distinct case when b.conn_suc_poor >= 3 or b.lte_highdrop_poor >= 3 or b.ho_out_suc_poor >= 3 or b.volte_join_poor >= 3
  301. or b.volte_highdrop_poor >= 3 or b.ul_pdcp_package_drop_poor >= 3 or b.dl_pdcp_package_drop_poor >= 3
  302. or c.cqi_poor = 1 or c.low_speed_mbps = 1 then b.eci end)*1.0/count(distinct b.eci)*100 poor_cell_ratio
  303. from a_pm_4g_poor_cell_day_tmp01 a
  304. join a_pm_4g_poor_cell_day_tmp02 b
  305. on a.eci = b.eci
  306. left join a_pm_4g_poor_cell_day_tmp03 c
  307. on b.eci = c.eci
  308. group by
  309. grouping sets((),(a.city),(a.city,a.county))';
  310. execute v_sql;
  311. /*
  312. *
  313. *
  314. *电信部分共建共享统计
  315. *
  316. *
  317. *
  318. */
  319. -- 电信小区区县信息表
  320. v_sql := 'drop table if exists a_pm_4g_poor_cell_day_tmp04';
  321. execute v_sql;
  322. v_sql := 'create temporary table a_pm_4g_poor_cell_day_tmp04
  323. (
  324. city varchar
  325. ,county varchar
  326. ,vendor varchar
  327. ,enbid integer
  328. ,cellid integer
  329. ,eci varchar
  330. ,cell_name varchar
  331. )';
  332. execute v_sql;
  333. v_sql := 'insert into a_pm_4g_poor_cell_day_tmp04
  334. (
  335. city
  336. ,county
  337. ,vendor
  338. ,enbid
  339. ,cellid
  340. ,eci
  341. ,cell_name
  342. )
  343. select
  344. city
  345. ,county
  346. ,vendor
  347. ,enbid
  348. ,cellid
  349. ,''127.''||enbid||''.''||cellid
  350. ,cell_name
  351. from pm_parse.pm_ct_cell_info_4g';
  352. execute v_sql;
  353. v_sql := 'drop table if exists a_pm_4g_poor_cell_day_tmp05';
  354. execute v_sql;
  355. v_sql := 'create temporary table a_pm_4g_poor_cell_day_tmp05
  356. (
  357. city varchar
  358. ,county varchar
  359. ,eci varchar
  360. ,conn_suc_poor integer
  361. ,lte_highdrop_poor integer
  362. ,ho_out_suc_poor integer
  363. ,volte_join_poor integer
  364. ,volte_highdrop_poor integer
  365. ,ul_pdcp_package_drop_poor integer
  366. ,dl_pdcp_package_drop_poor integer
  367. )';
  368. execute v_sql;
  369. v_sql := 'insert into a_pm_4g_poor_cell_day_tmp05
  370. (
  371. city
  372. ,county
  373. ,eci
  374. ,conn_suc_poor
  375. ,lte_highdrop_poor
  376. ,ho_out_suc_poor
  377. ,volte_join_poor
  378. ,volte_highdrop_poor
  379. ,ul_pdcp_package_drop_poor
  380. ,dl_pdcp_package_drop_poor
  381. )
  382. select
  383. a.city
  384. ,a.county
  385. ,a.eci
  386. ,count(distinct case when radio_conn_suc_r <= 0.9 and rrc_suc > 1000 then sdate end) conn_suc_poor
  387. ,count(distinct case when lte_drop_r >= 2 and lte_drop > 1000 then sdate end) lte_highdrop_poor
  388. ,count(distinct case when ho_out_suc_r <= 0.9 and (s1_ho_out_req+x2_ho_out_req) > 500 then sdate end) ho_out_suc_poor
  389. ,count(distinct case when erab_suc_r_qci1 < 0.98 or erab_suc_r_qci5 < 0.98 then sdate end) volte_join_poor
  390. ,count(distinct case when lte_drop_r_qci1 > 0.01 then sdate end) volte_highdrop_poor
  391. ,count(distinct case when ul_pdcp_package_drop_ratio_qci1 > 0.01 then sdate end) ul_pdcp_package_drop_poor
  392. ,count(distinct case when dl_pdcp_package_drop_ratio_qci1 > 0.01 then sdate end) dl_pdcp_package_drop_poor
  393. from a_pm_4g_poor_cell_day_tmp04 a
  394. join pm_parse.pm_4g_day b
  395. on b.sdate >= '''|| v_date ||'''::timestamp - ''6 day''::interval and b.sdate < '''|| v_date ||'''::timestamp + ''1 day''::interval
  396. and b.isp = ''电信''
  397. and a.eci = b.eci
  398. group by a.city,a.county,a.eci';
  399. execute v_sql;
  400. v_sql := 'drop table if exists busy_info_ct';
  401. execute v_sql;
  402. v_sql := 'create temporary table busy_info_ct
  403. (
  404. sdate timestamp
  405. ,eci varchar
  406. ,total_tra_mb numeric
  407. )';
  408. execute v_sql;
  409. v_sql := 'insert into busy_info_ct
  410. select
  411. date(sdate),eci,max(total_tra_mb)
  412. from pm_parse.pm_4g_hour b
  413. where b.sdate >= '''|| v_date ||'''::timestamp - ''6 day''::interval and b.sdate < '''|| v_date ||'''::timestamp + ''1 day''::interval
  414. and b.isp = ''电信''
  415. group by date(sdate),eci';
  416. execute v_sql;
  417. v_sql := 'drop table if exists a_pm_4g_poor_cell_day_tmp06';
  418. execute v_sql;
  419. v_sql := 'create temporary table a_pm_4g_poor_cell_day_tmp06
  420. (
  421. eci varchar
  422. ,cqi_poor integer
  423. ,highload_prb integer
  424. ,low_speed_mbps integer
  425. )';
  426. execute v_sql;
  427. v_sql := 'insert into a_pm_4g_poor_cell_day_tmp06
  428. (
  429. eci
  430. ,cqi_poor
  431. ,highload_prb
  432. ,low_speed_mbps
  433. )
  434. select
  435. eci
  436. ,case when sum(cqi_ge7)/7 > 0.2 then 1 else 0 end
  437. ,case when avg(dl_prb_utilization) > 0.65 then 1 else 0 end
  438. ,case when avg(dl_speed_mbps) < 5 then 1 else 0 end
  439. from (
  440. select
  441. t.sdate
  442. ,t.eci
  443. ,1-t.cqi_ge7 cqi_ge7
  444. ,t.dl_prb_utilization
  445. ,dl_speed_mbps
  446. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  447. from pm_parse.pm_4g_hour_'|| v_befor5_day_s ||' t
  448. join busy_info_ct a
  449. on a.sdate = '''|| v_befor5_day ||'''
  450. and t.eci = a.eci
  451. and t.total_tra_mb = a.total_tra_mb
  452. and t.isp = ''电信''
  453. union all
  454. select
  455. t.sdate
  456. ,t.eci
  457. ,1-t.cqi_ge7
  458. ,t.dl_prb_utilization
  459. ,dl_speed_mbps
  460. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  461. from pm_parse.pm_4g_hour_'|| v_befor4_day_s ||' t
  462. join busy_info_ct a
  463. on a.sdate = '''|| v_befor4_day ||'''
  464. and t.eci = a.eci
  465. and t.total_tra_mb = a.total_tra_mb
  466. and t.isp = ''电信''
  467. union all
  468. select
  469. t.sdate
  470. ,t.eci
  471. ,1-t.cqi_ge7
  472. ,t.dl_prb_utilization
  473. ,dl_speed_mbps
  474. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  475. from pm_parse.pm_4g_hour_'|| v_befor3_day_s ||' t
  476. join busy_info_ct a
  477. on a.sdate = '''|| v_befor3_day ||'''
  478. and t.eci = a.eci
  479. and t.total_tra_mb = a.total_tra_mb
  480. and t.isp = ''电信''
  481. union all
  482. select
  483. t.sdate
  484. ,t.eci
  485. ,1-t.cqi_ge7
  486. ,t.dl_prb_utilization
  487. ,dl_speed_mbps
  488. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  489. from pm_parse.pm_4g_hour_'|| v_befor2_day_s ||' t
  490. join busy_info_ct a
  491. on a.sdate = '''|| v_befor2_day ||'''
  492. and t.eci = a.eci
  493. and t.total_tra_mb = a.total_tra_mb
  494. and t.isp = ''电信''
  495. union all
  496. select
  497. t.sdate
  498. ,t.eci
  499. ,1-t.cqi_ge7
  500. ,t.dl_prb_utilization
  501. ,dl_speed_mbps
  502. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  503. from pm_parse.pm_4g_hour_'|| v_befor1_day_s ||' t
  504. join busy_info_ct a
  505. on a.sdate = '''|| v_befor1_day ||'''
  506. and t.eci = a.eci
  507. and t.total_tra_mb = a.total_tra_mb
  508. and t.isp = ''电信''
  509. union all
  510. select
  511. t.sdate
  512. ,t.eci
  513. ,1-t.cqi_ge7
  514. ,t.dl_prb_utilization
  515. ,dl_speed_mbps
  516. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  517. from pm_parse.pm_4g_hour_'|| v_befor_day_s ||' t
  518. join busy_info_ct a
  519. on a.sdate = '''|| v_befor_day ||'''
  520. and t.eci = a.eci
  521. and t.total_tra_mb = a.total_tra_mb
  522. and t.isp = ''电信''
  523. union all
  524. select
  525. t.sdate
  526. ,t.eci
  527. ,1-t.cqi_ge7
  528. ,t.dl_prb_utilization
  529. ,dl_speed_mbps
  530. ,row_number() over (partition by a.sdate,a.eci order by t.sdate desc) rn
  531. from pm_parse.pm_4g_hour_'|| vi_date ||' t
  532. join busy_info_ct a
  533. on a.sdate = '''|| v_date ||'''
  534. and t.eci = a.eci
  535. and t.total_tra_mb = a.total_tra_mb
  536. and t.isp = ''电信''
  537. ) tb
  538. where tb.rn = 1
  539. group by eci';
  540. execute v_sql;
  541. -- 插入目标数据
  542. v_sql := 'insert into app_screen.a_pm_4g_poor_cell_day
  543. (
  544. sdate
  545. ,city
  546. ,county
  547. ,operators
  548. ,share_cell_num
  549. ,conn_suc_poor
  550. ,lte_highdrop_poor
  551. ,cqi_poor
  552. ,low_speed_mbps
  553. ,ho_out_suc_poor
  554. ,volte_join_poor
  555. ,volte_highdrop_poor
  556. ,ul_pdcp_package_drop_poor
  557. ,dl_pdcp_package_drop_poor
  558. ,highload_prb
  559. ,poor_cell_num
  560. ,poor_cell_ratio
  561. )
  562. select
  563. '''|| v_date ||''' sdate
  564. ,coalesce(a.city,''合计'')
  565. ,coalesce(a.county,''合计'')
  566. ,''电信'' operators
  567. ,count(distinct b.eci) share_cell_num
  568. ,sum(case when b.conn_suc_poor >= 3 then 1 else 0 end)
  569. ,sum(case when b.lte_highdrop_poor >= 3 then 1 else 0 end)
  570. ,sum(c.cqi_poor)
  571. ,sum(c.low_speed_mbps)
  572. ,sum(case when b.ho_out_suc_poor >= 3 then 1 else 0 end)
  573. ,sum(case when b.volte_join_poor >= 3 then 1 else 0 end)
  574. ,sum(case when b.volte_highdrop_poor >= 3 then 1 else 0 end)
  575. ,sum(case when b.ul_pdcp_package_drop_poor >= 3 then 1 else 0 end)
  576. ,sum(case when b.dl_pdcp_package_drop_poor >= 3 then 1 else 0 end)
  577. ,sum(c.highload_prb)
  578. ,count(distinct case when b.conn_suc_poor >= 3 or b.lte_highdrop_poor >= 3 or b.ho_out_suc_poor >= 3 or b.volte_join_poor >= 3
  579. or b.volte_highdrop_poor >= 3 or b.ul_pdcp_package_drop_poor >= 3 or b.dl_pdcp_package_drop_poor >= 3
  580. or c.cqi_poor = 1 or c.low_speed_mbps = 1 then b.eci end) poor_cell_num
  581. ,count(distinct case when b.conn_suc_poor >= 3 or b.lte_highdrop_poor >= 3 or b.ho_out_suc_poor >= 3 or b.volte_join_poor >= 3
  582. or b.volte_highdrop_poor >= 3 or b.ul_pdcp_package_drop_poor >= 3 or b.dl_pdcp_package_drop_poor >= 3
  583. or c.cqi_poor = 1 or c.low_speed_mbps = 1 then b.eci end)*1.0/count(distinct b.eci)*100 poor_cell_ratio
  584. from a_pm_4g_poor_cell_day_tmp04 a
  585. join a_pm_4g_poor_cell_day_tmp05 b
  586. on a.eci = b.eci
  587. left join a_pm_4g_poor_cell_day_tmp06 c
  588. on b.eci = c.eci
  589. group by
  590. grouping sets((),(a.city),(a.city,a.county))';
  591. execute v_sql;
  592. return '0';
  593. END;
  594. $function$
  595. ;