14.sql 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. --14、单载频载扇能耗(月)
  2. ---北10
  3. --create table sqmdb_cost.rpt_dzpzs_cost_b10 as
  4. select fz.smonth,fz.sname,fz.cost_yw,fz.cost_hexin,
  5. (fz.cost_yw+fz.cost_hexin) as cost_total,
  6. fm.zps_num_no5g,
  7. case when fm.zps_num_no5g=0 then 0 else (fz.cost_yw+fz.cost_hexin)/fm.zps_num_no5g/3 end as cost_zps_no5g,
  8. case
  9. when fz.sname='北京' then 110000
  10. when fz.sname='天津' then 120000
  11. when fz.sname='河北' then 130000
  12. when fz.sname='山西' then 140000
  13. when fz.sname='内蒙古' then 150000
  14. when fz.sname='辽宁' then 210000
  15. when fz.sname='吉林' then 220000
  16. when fz.sname='黑龙江' then 230000
  17. when fz.sname='山东' then 370000
  18. when fz.sname='河南' then 410000
  19. end as prov_code
  20. from
  21. (select '202203' as smonth,sname,
  22. sum(column4+column5)/10000 as cost_yw,
  23. sum(column19)/10000 as cost_hexin
  24. from sqmdb_cost.report50
  25. where period_type='M'
  26. and sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
  27. and smonth between '202201' and '202203' group by sname) fz
  28. join
  29. (select smonth,sname,zps_total_no5g as zps_num_no5g
  30. from sqmdb_cost.jt_number_b10 where smonth='202203') fm
  31. on fz.sname=fm.sname
  32. --全省
  33. select fz.smonth,fz.sname,fz.cost_yw,fz.cost_hexin,
  34. (fz.cost_yw+fz.cost_hexin) as cost_total,
  35. fm.zps_num_with5g,
  36. case when fm.zps_num_with5g=0 then 0 else (fz.cost_yw+fz.cost_hexin)/fm.zps_num_with5g/4 end as cost_zps_with5g
  37. from
  38. (select '202204' as smonth,sname,
  39. sum(column4+column5)/10000 as cost_yw,
  40. sum(column19)/10000 as cost_hexin
  41. from sqmdb_cost.report50
  42. where period_type='M' and sname ='河北' and smonth between '202201' and '202204' group by sname) fz
  43. join
  44. (select a.city_name,(a.zps_total+b.zps_total)/10000/2 as zps_num_with5g from
  45. (select '河北' as city_name,zps_total from sqmdb_cost.zpzs_city where smonth='202112' and city_name='全省')a
  46. join
  47. (select '河北' as city_name,zps_total from sqmdb_cost.zpzs_city where smonth='202204' and city_name='全省')b
  48. on a.city_name=b.city_name) fm
  49. on fz.sname=fm.city_name
  50. ---地市
  51. select fz.smonth,fz.city_sname,fz.cost_yw,fz.cost_hexin,
  52. (fz.cost_yw+fz.cost_hexin) as cost_total,
  53. fm.zps_num_with5g,
  54. fm.zps_num_no5g,
  55. case when fm.zps_num_with5g=0 then 0 else (fz.cost_yw+fz.cost_hexin)/fm.zps_num_with5g/4 end as cost_zps_with5g,
  56. case when fm.zps_num_no5g=0 then 0 else (fz.cost_yw+fz.cost_hexin)/fm.zps_num_no5g/4 end as cost_zps_no5g,
  57. fz.city_code*100 as city_code
  58. from
  59. (select a.smonth,dg.city_sname,dg.city_code,a.cost_yw,a.cost_hexin from
  60. (select '202204' as smonth,sname,
  61. sum(column4+column5)/10000 as cost_yw,
  62. sum(column19)/10000 as cost_hexin
  63. from sqmdb_cost.report50
  64. where period_type='M'
  65. and sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
  66. and smonth between '202201' and '202204' group by sname) a
  67. join (select distinct city_code,city_sname,city_pro from sqmdb_cost.dict_grid) dg
  68. on a.sname=dg.city_pro) fz
  69. join
  70. (select
  71. city_name,
  72. zps_total_with5g as zps_num_with5g,
  73. zps_total_no5g as zps_num_no5g
  74. from sqmdb_cost.jt_number_city where month_id='202204') fm
  75. on fz.city_sname=fm.city_name
  76. order by fz.city_code
  77. --单载频载扇能耗--网格
  78. --create table sqmdb_cost.rpt_dzpzs_cost_grid_1 as
  79. select fm.smonth,dcg.city_name,dcg.grid_name,fz.cost_yw,fz.cost_hexin,
  80. (fz.cost_yw+fz.cost_hexin) as cost_total,
  81. fm.zps_num_with5g,
  82. fm.zps_num_no5g,
  83. case when fm.zps_num_with5g=0 then 0 else (fz.cost_yw+fz.cost_hexin)/fm.zps_num_with5g/4 end as cost_zps_with5g,
  84. null cost_zps_no5g,
  85. dcg.city_code,dcg.area_code
  86. from
  87. (select jt.smonth,jt.city_name,jt.grid_name,jt.cost_yw,jt.cost_hexin,dgc.grid_code from
  88. (select smonth,city_name_short(city_name) as city_name,grid_name,(column4+column5) as cost_yw,column19 as cost_hexin
  89. from sqmdb_cost.report49 where period_type='Y' and smonth='202204')jt
  90. left join sqmdb_cost.dict_grid_code dgc on jt.city_name=dgc.city_name and trim(jt.grid_name)=trim(dgc.grid_name)
  91. where dgc.grid_code is not null) fz
  92. join
  93. (select z1.smonth,z1.city_name as city_name,z1.grid_name,
  94. z2.zps_num_total as zps_num_total_ly,
  95. z1.zps_num_total as zps_num_total_cm,
  96. avg_num(z1.zps_num_total,z2.zps_num_total) as zps_num_with5g,
  97. null as zps_num_no5g,
  98. dgc1.grid_code
  99. from
  100. (select * from sqmdb_cost.zpzs where smonth='202204') z1
  101. join
  102. (select * from sqmdb_cost.zpzs where smonth='202112') z2
  103. on trim(z1.city_name)=trim(z2.city_name) and trim(z1.grid_name)=trim(z2.grid_name)
  104. left join sqmdb_cost.dict_grid_code dgc1 on trim(z1.city_name)=trim(dgc1.city_name) and trim(z1.grid_name)=trim(dgc1.grid_name)
  105. where dgc1.grid_code is not null) fm
  106. on fz.grid_code=fm.grid_code
  107. left join sqmdb_cost.dict_code_grid dcg on fz.grid_code=dcg.grid_code