大屏_比别人.sql 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. --02、网运成本占收比(省内口径)
  2. --chengben_other_1_city_b10_202203.csv
  3. select t1.*,
  4. case
  5. when sname='北京' then 110000
  6. when sname='天津' then 120000
  7. when sname='河北' then 130000
  8. when sname='山西' then 140000
  9. when sname='内蒙古' then 150000
  10. when sname='辽宁' then 210000
  11. when sname='吉林' then 220000
  12. when sname='黑龙江' then 230000
  13. when sname='山东' then 370000
  14. when sname='河南' then 410000
  15. else t2.city_code*100 end as city_code
  16. from
  17. (select smonth,stype,sname,cost_total,income,
  18. cost_total/income as cost_income_rate
  19. from sqmdb_cost.chengben_shengnei
  20. --where stype='北10'
  21. --where stype='地市'
  22. where smonth='202203') t1
  23. left join
  24. (select distinct city_code,city_pro from sqmdb_cost.dict_grid) t2
  25. on t1.sname=t2.city_pro
  26. --14、单载频载扇能耗(月)
  27. ---地市
  28. ---chengben_other_2_city_202203.csv
  29. select fm.smonth,fz.city_sname,fz.cost_yw,fz.cost_hexin,
  30. (fz.cost_yw+fz.cost_hexin) as cost_total,
  31. fm.zps_num_with5g,
  32. fm.zps_num_no5g,
  33. case when fm.zps_num_with5g=0 then 0 else (fz.cost_yw+fz.cost_hexin)/fm.zps_num_with5g end as cost_zps_with5g,
  34. case when fm.zps_num_no5g=0 then 0 else (fz.cost_yw+fz.cost_hexin)/fm.zps_num_no5g end as cost_zps_no5g,
  35. fz.city_code*100 as city_code
  36. from
  37. (select a.smonth,a.sname,dg.city_sname,dg.city_code,a.cost_yw,a.cost_hexin from
  38. (select smonth,sname,
  39. (column4+column5) as cost_yw,
  40. column19 as cost_hexin
  41. from sqmdb_cost.report50
  42. where period_type='M'
  43. and sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
  44. and smonth='202203') a
  45. join (select distinct city_code,city_sname,city_pro from sqmdb_cost.dict_grid) dg
  46. on a.sname=dg.city_pro) fz
  47. join
  48. (select z1.smonth,z1.city_name,
  49. sum(round((coalesce(z1.zps_num_234g,0)+coalesce(z2.zps_num_234g,0)+coalesce(z1.zps_num_5g, 0)+coalesce(z2.zps_num_5g,0))/2)) as zps_num_with5g,
  50. sum(round((coalesce(z1.zps_num_234g,0)+coalesce(z2.zps_num_234g,0))/2)) as zps_num_no5g
  51. from
  52. (select * from sqmdb_cost.zpzs where smonth='202203') z1
  53. left join
  54. (select * from sqmdb_cost.zpzs where smonth='202112') z2
  55. on z1.city_name=z2.city_name and z1.grid_name=z2.grid_name group by z1.smonth,z1.city_name) fm
  56. on fz.city_sname=fm.city_name
  57. order by fz.city_code
  58. ---网格新(49直接关联载频载扇里的网格名称)
  59. ---chengben_other_2_grid_202203.csv
  60. select fm.smonth,fz.city_name,fz.grid_name,fz.cost_yw,fz.cost_hexin,
  61. (fz.cost_yw+fz.cost_hexin) as cost_total,
  62. fm.zps_num_with5g,
  63. fm.zps_num_no5g,
  64. case when fm.zps_num_with5g=0 then 0 else (fz.cost_yw+fz.cost_hexin)/fm.zps_num_with5g end as cost_zps_with5g,
  65. case when fm.zps_num_no5g=0 then 0 else (fz.cost_yw+fz.cost_hexin)/fm.zps_num_no5g end as cost_zps_no5g,
  66. dg.city_code*100 as city_code,
  67. dg2.area_code
  68. from
  69. (select smonth,city_name,grid_name,
  70. (column4+column5) as cost_yw,
  71. column19 as cost_hexin
  72. from sqmdb_cost.report49
  73. where period_type='M'
  74. and smonth='202203') fz
  75. join
  76. (select z1.smonth,'河北_'||z1.city_name as city_name,z1.grid_name,
  77. round((coalesce(z1.zps_num_234g,0)+coalesce(z2.zps_num_234g,0)+coalesce(z1.zps_num_5g, 0)+coalesce(z2.zps_num_5g,0))/2) as zps_num_with5g,
  78. round((coalesce(z1.zps_num_234g,0)+coalesce(z2.zps_num_234g,0))/2) as zps_num_no5g
  79. from
  80. (select * from sqmdb_cost.zpzs where smonth='202203') z1
  81. left join
  82. (select * from sqmdb_cost.zpzs where smonth='202112') z2
  83. on z1.city_name=z2.city_name and z1.grid_name=z2.grid_name) fm
  84. on fz.city_name=fm.city_name and trim(fz.grid_name)=trim(fm.grid_name)
  85. left join
  86. (select distinct city_code,city_sname,grid_city_name from sqmdb_cost.dict_grid) dg
  87. on fz.city_name=dg.grid_city_name
  88. left join
  89. (select distinct area_code,grid_name from sqmdb_cost.dict_grid) dg2
  90. on trim(fz.grid_name)=trim(dg2.grid_name)
  91. where fz.grid_name!='合计'
  92. order by dg.city_code,dg2.area_code
  93. --13、单端口能耗成本(月)
  94. ---地市
  95. ---chengben_other_3_city_202203.csv
  96. select ta1.*,ta2.city_code*100 as city_code from
  97. (select t1.smonth,t1.city_name,t1.cost_nenghao,t2.ftth_port_count,
  98. t1.cost_nenghao/t2.ftth_port_count as cost_port_nenghao
  99. from
  100. (select distinct a.smonth,dg.city_name,a.cost_nenghao from
  101. (select smonth,sname,stype,
  102. (column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115+column4)-column5-column19-column108 as cost_nenghao
  103. from sqmdb_cost.report50 r
  104. where stype ='北方省汇总展现'
  105. and sname in ('河北省本部','石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
  106. and smonth='202203') a
  107. join sqmdb_cost.dict_grid dg
  108. on a.sname=dg.city_pro) t1
  109. join
  110. (select distinct dg.city_name,a.ftth_port_count from
  111. (select sdate,local_net_name,sum(ftth_port_count) as ftth_port_count
  112. from sqmdb_cost.kuandai_ftth
  113. where areal_type_name='小计' and sdate='2022-04-02 00:00:00'
  114. group by sdate,local_net_name) a
  115. join sqmdb_cost.dict_grid dg
  116. on a.local_net_name=dg.grid_city_kd) t2
  117. on t1.city_name=t2.city_name) ta1
  118. left join
  119. (select distinct city_code,city_name from sqmdb_cost.dict_grid) ta2
  120. on ta1.city_name=ta2.city_name
  121. order by ta2.city_code
  122. ---网格
  123. ---chengben_other_3_grid_202203.csv
  124. select ta1.*,ta2.city_code*100 as city_code,ta3.area_code from
  125. (select t1.smonth,t1.city_name,t1.area_name,t1.cost_nenghao,t2.ftth_port_count,
  126. t1.cost_nenghao/t2.ftth_port_count as cost_port_nenghao
  127. from
  128. (select fz.smonth,dg.city_name,dg.area_name,fz.cost_nenghao from
  129. (select smonth,period_type,segment1_name,city_code,city_name,grid_code,grid_name,
  130. (column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115+column4)-column5-column19-column108 as cost_nenghao
  131. from sqmdb_cost.report49
  132. where period_type='M' and grid_name!='合计' and smonth='202203') fz
  133. join sqmdb_cost.dict_grid dg
  134. on fz.city_code=dg.grid_city_code::varchar and fz.grid_code=dg.grid_code::varchar) t1
  135. join
  136. (select dg.city_name,dg.area_name,a.ftth_port_count from
  137. (select sdate,local_net_name,area_name,sum(ftth_port_count) as ftth_port_count
  138. from sqmdb_cost.kuandai_ftth
  139. where areal_type_name!='小计' and sdate='2022-04-02 00:00:00'
  140. group by sdate,local_net_name,area_name) a
  141. join sqmdb_cost.dict_grid dg
  142. on a.local_net_name=dg.grid_city_kd and a.area_name=dg.grid_name_kd) t2
  143. on t1.city_name=t2.city_name and t1.area_name=t2.area_name) ta1
  144. left join
  145. (select distinct city_code,city_name from sqmdb_cost.dict_grid) ta2
  146. on ta1.city_name=ta2.city_name
  147. left join
  148. (select distinct city_code,city_name,area_code,area_name from sqmdb_cost.dict_grid) ta3
  149. on ta1.city_name=ta3.city_name and ta1.area_name=ta3.area_name
  150. order by ta2.city_code,ta3.area_code
  151. --16、单站铁塔租赁费(月)
  152. ---北10数据(select * from sqmdb_cost.report50016)
  153. ---chengben_other_4_b10_202203.csv
  154. select smonth,sname,column1 as tower_cost_avg_b10,
  155. case
  156. when sname='北京' then 110000
  157. when sname='天津' then 120000
  158. when sname='河北' then 130000
  159. when sname='山西' then 140000
  160. when sname='内蒙古' then 150000
  161. when sname='辽宁' then 210000
  162. when sname='吉林' then 220000
  163. when sname='黑龙江' then 230000
  164. when sname='山东' then 370000
  165. when sname='河南' then 410000
  166. end as prov_code
  167. from sqmdb_cost.report50016
  168. where sname in ('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
  169. and smonth='202203'
  170. order by case
  171. when sname='北京' then 1
  172. when sname='天津' then 2
  173. when sname='河北' then 3
  174. when sname='山西' then 4
  175. when sname='内蒙古' then 5
  176. when sname='辽宁' then 6
  177. when sname='吉林' then 7
  178. when sname='黑龙江' then 8
  179. when sname='山东' then 9
  180. when sname='河南' then 10
  181. end
  182. ---网格
  183. ---chengben_other_4_grid_202203.csv
  184. select t1.*,
  185. t2.city_code*100 as city_code,
  186. t3.area_code
  187. from
  188. (select sdate,city_operator,area_operator,
  189. sum(total_cost) as tower_cost_total,
  190. count(*) as tower_num,
  191. sum(total_cost)/count(*) as tower_cost_avg_area
  192. from (
  193. select sdate,city_operator,area_operator,site_addr_id,sum(total_cost) as total_cost from
  194. sqmdb_cost.tower2 t group by sdate,city_operator,area_operator,site_addr_id) tmp group by sdate,city_operator,area_operator) t1
  195. left join
  196. (select distinct city_code,city_name from sqmdb_cost.dict_grid) t2
  197. on t1.city_operator=t2.city_name
  198. left join
  199. (select distinct city_code,city_name,area_code,area_tower from sqmdb_cost.dict_grid) t3
  200. on t1.city_operator=t3.city_name and t1.area_operator=t3.area_tower
  201. where t1.sdate='202203'
  202. order by t2.city_code,t3.area_code