16.sql 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. --16、单站铁塔租赁费(月)
  2. ---北10数据(select * from sqmdb_cost.report50016)
  3. select
  4. smonth as MONTH_ID,
  5. '北10' as ZB_TYPE,
  6. sname as PROV_NAME,
  7. null as CITY_ID,
  8. null as CITY_NAME,
  9. null as GRID_ID,
  10. null as GRID_NAME,
  11. '16' as ZB_CODE,
  12. '单站铁塔租赁费(月)' as ZB_NAME,
  13. column2*10000 as QZ_FZ,
  14. column5 as QZ_FM,
  15. column2*10000/column5/4 as BY_QZ
  16. from sqmdb_cost.report50016
  17. where sname in ('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
  18. and smonth='202204'
  19. --北10
  20. select
  21. smonth,
  22. sname,
  23. column2*10000 as tower_cost,
  24. column4 as tower_num_ly,
  25. column3 as tower_num_cm,
  26. (column3+column4)/2 as tower_num_avg,
  27. column2*10000/((column3+column4)/2)/4 as tower_cost_avg
  28. from sqmdb_cost.report50016
  29. where sname in ('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
  30. and smonth='202204'
  31. --河北省
  32. select smonth,sname,column1 as tower_cost_avg_prov from sqmdb_cost.report50016 where smonth='202204' and sname='河北'
  33. ---地市
  34. --create table sqmdb_cost.rpt_tower_cost_city as
  35. select
  36. '202204' as smonth,
  37. (regexp_split_to_array(tc.sname,'_'))[1] as city_name,
  38. tc.tower_cost,
  39. tn.tower_num_ly,
  40. tn.tower_num_cm,
  41. tn.tower_num_avg,
  42. (tc.tower_cost/tn.tower_num_avg)/4 as tower_cost_avg
  43. from
  44. (select sname,sum(column2+column3) as tower_cost from sqmdb_cost.report50 r
  45. where period_type='M' and smonth between '202201' and '202204' group by sname)tc
  46. join
  47. (with tower_code as (select distinct sdate,city_operator,site_addr_id from sqmdb_cost.tower3 where stype!='室分'
  48. union all
  49. select sdate,city_operator,site_addr_id from sqmdb_cost.tower3 where stype='室分')
  50. select
  51. dg.city_code,
  52. dg.city_pro,
  53. t1.tower_num_ly,
  54. t2.tower_num_cm,
  55. (t1.tower_num_ly+t2.tower_num_cm)/2 as tower_num_avg
  56. from
  57. (select city_operator,count(*) as tower_num_ly from tower_code where sdate='202112' group by city_operator)t1
  58. join
  59. (select city_operator,count(*) as tower_num_cm from tower_code where sdate='202204' group by city_operator)t2
  60. on t1.city_operator=t2.city_operator
  61. join
  62. (select distinct city_code,city_name,city_pro from sqmdb_cost.dict_grid)dg
  63. on t1.city_operator=dg.city_name) tn
  64. on tc.sname=tn.city_pro
  65. ---网格---网格名称+区县名称
  66. --drop table sqmdb_cost.rpt_tower_cost_grid
  67. --create table sqmdb_cost.rpt_tower_cost_grid as
  68. select
  69. tc.smonth,
  70. (regexp_split_to_array(tc.city_name,'_'))[2] as city_name,
  71. tn.area_name,
  72. tn.area_tower,
  73. tc.grid_name,
  74. tc.tower_cost,
  75. tn.tower_num_ly,
  76. tn.tower_num_cm,
  77. tn.tower_num_avg,
  78. (tc.tower_cost/tn.tower_num_avg)/4 as tower_cost_avg
  79. from
  80. (select smonth,city_name,grid_name,(column2+column3) as tower_cost from sqmdb_cost.report49 r
  81. where period_type='Y' and smonth='202204')tc
  82. join
  83. (with tower_code as (
  84. select distinct sdate,city_operator,area_operator,site_addr_id from sqmdb_cost.tower3 where stype!='室分'
  85. union all
  86. select sdate,city_operator,area_operator,site_addr_id from sqmdb_cost.tower3 where stype='室分')
  87. select
  88. dg.city_code,
  89. dg.area_name,
  90. dg.area_tower,
  91. dg.grid_city_name,
  92. dg.grid_name,
  93. t1.area_operator,
  94. t1.tower_num_ly,
  95. t2.tower_num_cm,
  96. (t1.tower_num_ly+t2.tower_num_cm)/2 as tower_num_avg
  97. from
  98. (select city_operator,area_operator,count(*) as tower_num_ly from tower_code where sdate='202112' group by city_operator,area_operator)t1
  99. join
  100. (select city_operator,area_operator,count(*) as tower_num_cm from tower_code where sdate='202204' group by city_operator,area_operator)t2
  101. on t1.city_operator=t2.city_operator and t1.area_operator=t2.area_operator
  102. join
  103. (select distinct city_code,city_name,area_name,grid_city_name,grid_name,area_tower from sqmdb_cost.dict_grid)dg
  104. on t1.city_operator=dg.city_name and t1.area_operator=dg.area_tower) tn
  105. on tc.city_name=tn.grid_city_name and trim(tc.grid_name)=trim(tn.grid_name)
  106. ---网格---使用铁塔预提表计算网格站点数
  107. --drop table sqmdb_cost.rpt_tower_cost_grid_1
  108. --create table sqmdb_cost.rpt_tower_cost_grid_1 as
  109. select
  110. tc.smonth,
  111. tc.city_name,
  112. dcg.city_code*100 as city_code,
  113. dcg.grid_name,
  114. dcg.grid_code,
  115. --tn.area_name,
  116. --tn.area_tower,
  117. --tc.grid_name,
  118. tc.tower_cost,
  119. tn.tower_num_ly,
  120. tn.tower_num_cm,
  121. tn.tower_num_avg,
  122. (tc.tower_cost/tn.tower_num_avg)/4 as tower_cost_avg
  123. from
  124. (select t1.smonth,t1.city_name,t1.tower_cost,t2.grid_code
  125. from
  126. (select smonth,city_name_short(city_name) as city_name,grid_name,(column2+column3) as tower_cost from sqmdb_cost.report49 r where period_type='Y' and smonth='202204')t1
  127. left join sqmdb_cost.dict_grid_code t2 on t1.city_name=t2.city_name and trim(t1.grid_name)=trim(t2.grid_name)
  128. where t2.grid_code is not null)tc
  129. join
  130. (select yt.city_name,dgc.grid_code,yt.tower_num_ly,yt.tower_num_cm,yt.tower_num_avg from
  131. (select a.city_name,a.cbzx,b.tower_num_ly,a.tower_num_cm,
  132. avg_num(a.tower_num_cm,b.tower_num_ly) as tower_num_avg
  133. from
  134. (select city_name,cbzx,count(*) as tower_num_cm from sqmdb_cost.tower_yuti where tower_code is not null and smonth='202204' group by city_name,cbzx) a
  135. join
  136. (select city_name,cbzx,count(*) as tower_num_ly from sqmdb_cost.tower_yuti where tower_code is not null and smonth='202112' group by city_name,cbzx) b
  137. on a.city_name=b.city_name and a.cbzx=b.cbzx) yt
  138. left join sqmdb_cost.dict_grid_code dgc on yt.city_name=dgc.city_name and trim(yt.cbzx)=trim(dgc.grid_name)) tn
  139. on tc.grid_code=tn.grid_code
  140. left join sqmdb_cost.dict_code_grid dcg on tc.grid_code=dcg.grid_code