ソースを参照

上传文档及相关SQL脚本

lieyingthh 2 年 前
コミット
3ee05daa05
100 ファイル変更3933 行追加0 行削除
  1. 44 0
      Scripts/01.sql
  2. 82 0
      Scripts/01_08_10_19.sql
  3. 12 0
      Scripts/02.sql
  4. 33 0
      Scripts/03.sql
  5. 32 0
      Scripts/05.sql
  6. 27 0
      Scripts/06.sql
  7. 41 0
      Scripts/07.sql
  8. 39 0
      Scripts/08.sql
  9. 24 0
      Scripts/09.sql
  10. 12 0
      Scripts/10.sql
  11. 53 0
      Scripts/11.sql
  12. 78 0
      Scripts/12_13.sql
  13. 114 0
      Scripts/14.sql
  14. 21 0
      Scripts/15.sql
  15. 151 0
      Scripts/16.sql
  16. 16 0
      Scripts/17.sql
  17. 34 0
      Scripts/18.sql
  18. 37 0
      Scripts/19.sql
  19. 20 0
      Scripts/20.sql
  20. 22 0
      Scripts/21.sql
  21. 25 0
      Scripts/22.sql
  22. 30 0
      Scripts/23.sql
  23. 49 0
      Scripts/24.sql
  24. 56 0
      Scripts/25.sql
  25. 30 0
      Scripts/26.sql
  26. 14 0
      Scripts/29_30.sql
  27. 41 0
      Scripts/IDC报表.sql
  28. 31 0
      Scripts/SDR汇聚表检查.sql
  29. 17 0
      Scripts/bigscreen/chengben_center_city.sql
  30. 42 0
      Scripts/bigscreen/chengben_exception_1_grid.sql
  31. 28 0
      Scripts/bigscreen/chengben_exception_2_grid.sql
  32. 19 0
      Scripts/bigscreen/chengben_exception_3_grid.sql
  33. 25 0
      Scripts/bigscreen/chengben_other_1_city_b10.sql
  34. 15 0
      Scripts/bigscreen/chengben_other_2_b10.sql
  35. 17 0
      Scripts/bigscreen/chengben_other_2_city.sql
  36. 24 0
      Scripts/bigscreen/chengben_other_2_grid.sql
  37. 23 0
      Scripts/bigscreen/chengben_other_3_b10.sql
  38. 16 0
      Scripts/bigscreen/chengben_other_3_city.sql
  39. 14 0
      Scripts/bigscreen/chengben_other_3_grid.sql
  40. 31 0
      Scripts/bigscreen/chengben_other_4_b10.sql
  41. 15 0
      Scripts/bigscreen/chengben_other_4_city.sql
  42. 20 0
      Scripts/bigscreen/chengben_other_4_grid.sql
  43. 21 0
      Scripts/bigscreen/chengben_quzhun_1_a_grid.sql
  44. 21 0
      Scripts/bigscreen/chengben_quzhun_1_b_grid.sql
  45. 34 0
      Scripts/bigscreen/chengben_quzhun_1_c_grid.sql
  46. 16 0
      Scripts/bigscreen/chengben_quzhun_1_d_city.sql
  47. 23 0
      Scripts/bigscreen/chengben_quzhun_1_d_grid.sql
  48. 34 0
      Scripts/bigscreen/chengben_quzhun_1_e_grid.sql
  49. 21 0
      Scripts/bigscreen/chengben_quzhun_2_city.sql
  50. 19 0
      Scripts/bigscreen/chengben_quzhun_3_city.sql
  51. 18 0
      Scripts/bigscreen/chengben_quzhun_4_city.sql
  52. 35 0
      Scripts/bigscreen/chengben_self_1_b10.sql
  53. 37 0
      Scripts/bigscreen/chengben_self_2_city.sql
  54. 239 0
      Scripts/bigscreen_new/T_NET_COST_MAG_MON.sql
  55. 241 0
      Scripts/bigscreen_new/T_NET_COST_MAG_MON_旧版累计成本.sql
  56. 512 0
      Scripts/bigscreen_new/T_NET_COST_MAG_TAB_ERROR_MON.sql
  57. 114 0
      Scripts/bigscreen_new/T_NET_COST_MAG_TAB_KPI_MON.sql
  58. 18 0
      Scripts/kpi31/01_b10.sql
  59. 27 0
      Scripts/kpi31/01_city.sql
  60. 20 0
      Scripts/kpi31/02_b10.sql
  61. 25 0
      Scripts/kpi31/02_city.sql
  62. 19 0
      Scripts/kpi31/03_b10.sql
  63. 25 0
      Scripts/kpi31/04_city.sql
  64. 24 0
      Scripts/kpi31/05_b10.sql
  65. 28 0
      Scripts/kpi31/05_city.sql
  66. 24 0
      Scripts/kpi31/06_b10.sql
  67. 28 0
      Scripts/kpi31/06_city.sql
  68. 28 0
      Scripts/kpi31/07_b10.sql
  69. 32 0
      Scripts/kpi31/07_city.sql
  70. 19 0
      Scripts/kpi31/08_b10.sql
  71. 28 0
      Scripts/kpi31/08_city.sql
  72. 23 0
      Scripts/kpi31/09_b10.sql
  73. 27 0
      Scripts/kpi31/09_city.sql
  74. 20 0
      Scripts/kpi31/10_b10.sql
  75. 25 0
      Scripts/kpi31/10_city.sql
  76. 38 0
      Scripts/kpi31/11_city.sql
  77. 38 0
      Scripts/kpi31/11_grid.sql
  78. 22 0
      Scripts/kpi31/12_city.sql
  79. 19 0
      Scripts/kpi31/12_grid.sql
  80. 18 0
      Scripts/kpi31/13_b10.sql
  81. 22 0
      Scripts/kpi31/13_city.sql
  82. 20 0
      Scripts/kpi31/13_grid.sql
  83. 18 0
      Scripts/kpi31/14_b10.sql
  84. 19 0
      Scripts/kpi31/14_city.sql
  85. 18 0
      Scripts/kpi31/14_grid.sql
  86. 37 0
      Scripts/kpi31/15_city.sql
  87. 19 0
      Scripts/kpi31/16_b10.sql
  88. 22 0
      Scripts/kpi31/16_city.sql
  89. 18 0
      Scripts/kpi31/16_grid.sql
  90. 29 0
      Scripts/kpi31/17_city.sql
  91. 29 0
      Scripts/kpi31/17_grid.sql
  92. 25 0
      Scripts/kpi31/18_b10.sql
  93. 30 0
      Scripts/kpi31/18_city.sql
  94. 24 0
      Scripts/kpi31/19_b10.sql
  95. 29 0
      Scripts/kpi31/19_city.sql
  96. 28 0
      Scripts/kpi31/20_city.sql
  97. 26 0
      Scripts/kpi31/20_grid.sql
  98. 28 0
      Scripts/kpi31/21_city.sql
  99. 29 0
      Scripts/kpi31/21_grid.sql
  100. 29 0
      Scripts/kpi31/22_city.sql

+ 44 - 0
Scripts/01.sql

@@ -0,0 +1,44 @@
+--01、网运成本占收比(集团口径)
+---北10
+select 
+smonth,
+sname,
+column6 as cost_with_rengong,
+column10 as cost_no_rengong,
+column14 as income,
+column6/column14 rate_with_rengong,
+column10/column14 rate_no_rengong
+--column17 as 网运成本占收比(含人工),
+--column20 as 网运成本占收比(不含人工)
+from sqmdb_cost.report50003 
+where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202203'
+
+
+---地市
+select 
+a.smonth,
+a.sname,
+a.cost_total,
+b.income_year, --本年收入累计,
+case when b.income_year=0 then null else a.cost_total/b.income_year end as cost_rate--网运成本占收比(集团口径)
+--c.city_code
+from
+(select '202203' as smonth,sname,
+sum(column1)/10000 as cost_total--成本合计(包含人工)
+from sqmdb_cost.report50 where smonth between '202201' and '202203' group by sname) a 
+left join
+(select report_id,smonth,sname,stype,column4 as income_year from sqmdb_cost.report80040) b 
+on a.smonth=b.smonth and a.sname=b.sname
+left join
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid) c 
+on a.sname=c.city_pro
+where a.sname in ('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and a.smonth='202203'
+
+
+
+---网格(网格数据缺少分母)-目前只有分子
+select smonth,segment1_name,city_name,grid_name,
+column1 as cost_total
+from sqmdb_cost.report49

+ 82 - 0
Scripts/01_08_10_19.sql

@@ -0,0 +1,82 @@
+--01、网运成本占收比(集团口径)
+---地市
+select 
+a.smonth as 月份,
+a.sname as 公司,
+a.stype as 数据类型,
+a.cost_total as 费用合计,
+a.cost_total2 as 费用合计含账面人工,
+a.cost_total2-a.cost_people as 费用合计去账面人工,
+a.cost_people as 账面人工成本,
+a.cost_nenghao as 网络能耗,
+a.cost_fix as 修理维护费,
+a.cost_wireless as 无线网成本,
+a.cost_rental_3rd as 第三方租赁费,
+a.cost_rental_tower as 铁塔租赁费,
+b.income_year as 本年收入累计,
+b.stype as 本年收入累计类型,
+case when b.income_year=0 then null else a.cost_total/b.income_year end as 网运成本占收比(集团口径),
+case when b.income_year=0 then null else a.cost_nenghao/b.income_year end as 网络能耗占收比,
+case when b.income_year=0 then null else a.cost_fix/b.income_year end as 修理维护费占收比,
+case when b.income_year=0 then null else a.cost_wireless/b.income_year end as 无线成本占收比
+from
+(select smonth,sname,stype,
+(column10+column23+column31+column45+column53+column61+column67+column74+column81+column90+column103+column109+column116+column6+column20+column28+column42+column50+column58+column71+column79+column87+column101+column7+column21+column29+column43+column51+column59+column65+column72+column80+column88+column96+column102+column11+column24+column32+column46+column54+column62+column68+column75+column82+column91+column104+column9+column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115+column4+column2+column3+column12+column15+column16+column25+column35+column39+column38+column47+column55+column63+column76+column83+column92+column105+column111+column118+column13+column14+column36+column37+column95+column112+column113+column33+column34+column17+column8+column22+column30+column44+column52+column60+column66+column73+column85+column89+column97+column106+column110+column117+column99+column120)/10000 as cost_total,
+(column115+column116+column117+column118+column119+column108+column109+column110+column111+column112+column113+column114+column100+column101+column102+column103+column104+column105+column106+column107+column99+column94+column95+column96+column97+column98+column86+column87+column88+column89+column90+column91+column92+column93+column78+column79+column80+column81+column82+column83+column84+column85+column70+column71+column72+column73+column74+column75+column76+column77+column65+column66+column67+column68+column69+column57+column58+column59+column60+column61+column62+column63+column64+column49+column50+column51+column52+column53+column54+column55+column56+column41+column42+column43+column44+column45+column46+column47+column48+column27+column28+column29+column30+column31+column32+column33+column34+column35+column36+column37+column38+column39+column40+column19+column20+column21+column22+column23+column24+column25+column26+column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18+column120)/10000 as cost_total2,
+(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18-column18)/10000 as cost_wireless,
+(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115+column4)/10000 as cost_nenghao,
+(column10+column23+column31+column45+column53+column61+column67+column74+column81+column90+column103+column109+column116+column6+column20+column28+column42+column50+column58+column71+column79+column87+column101+column7+column21+column29+column43+column51+column59+column65+column72+column80+column88+column96+column102+column11+column24+column32+column46+column54+column62+column68+column75+column82+column91+column104+column9)/10000 as cost_fix,
+(column12+column15+column16)/10000 as cost_rental_3rd,
+(column2+column3)/10000 as cost_rental_tower,
+(column119+column114+column107+column98+column93+column84+column77+column69+column64+column56+column48+column40+column26+column18)/10000 as cost_people
+from sqmdb_cost.report50 where stype ='北方省汇总展现') a
+left join
+(select report_id,smonth,sname,stype,column4 as income_year from sqmdb_cost.report80040) b
+on a.smonth=b.smonth and a.sname=b.sname
+where 
+--a.sname like '%河北%'
+a.sname in ('北方10省合计','河北省本部','石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北','廊坊数据分公司_河北')
+--a.sname in ('河北省本部')
+and a.smonth='202202'
+
+
+--1、网运成本占收比(集团口径)
+--网格(网格数据缺少分母)
+select 
+a.smonth as 月份,
+a.segment1_name as 公司,
+a.city_name as 地市,
+a.grid_name as 网格,
+a.cost_total as 费用合计,
+a.cost_total2 as 费用合计含账面人工,
+a.cost_total2-a.cost_people as 费用合计去账面人工,
+a.cost_people as 账面人工成本,
+a.cost_bai as 网络能耗,
+a.cost_fix as 修理维护费,
+a.cost_wireless as 无线网成本,
+a.cost_rental_3rd as 第三方租赁费,
+a.cost_rental_tower as 铁塔租赁费,
+b.income_year as 本年收入累计,
+case when b.income_year=0 then null else a.cost_total/b.income_year end as 网运成本占收比(集团口径),
+case when b.income_year=0 then null else a.cost_bai/b.income_year*100 end as 网络能耗占收比,
+case when b.income_year=0 then null else a.cost_fix/b.income_year end as 修理维护费占收比,
+case when b.income_year=0 then null else a.cost_wireless/b.income_year end as 无线成本占收比
+from
+(select smonth,segment1_name,city_name,grid_name,
+(column10+column23+column31+column45+column53+column61+column67+column74+column81+column90+column103+column109+column116+column6+column20+column28+column42+column50+column58+column71+column79+column87+column101+column7+column21+column29+column43+column51+column59+column65+column72+column80+column88+column96+column102+column11+column24+column32+column46+column54+column62+column68+column75+column82+column91+column104+column9+column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115+column4+column2+column3+column12+column15+column16+column25+column35+column39+column38+column47+column55+column63+column76+column83+column92+column105+column111+column118+column13+column14+column36+column37+column95+column112+column113+column33+column34+column17+column8+column22+column30+column44+column52+column60+column66+column73+column85+column89+column97+column106+column110+column117+column99+column120)/10000 as cost_total,
+(column115+column116+column117+column118+column119+column108+column109+column110+column111+column112+column113+column114+column100+column101+column102+column103+column104+column105+column106+column107+column99+column94+column95+column96+column97+column98+column86+column87+column88+column89+column90+column91+column92+column93+column78+column79+column80+column81+column82+column83+column84+column85+column70+column71+column72+column73+column74+column75+column76+column77+column65+column66+column67+column68+column69+column57+column58+column59+column60+column61+column62+column63+column64+column49+column50+column51+column52+column53+column54+column55+column56+column41+column42+column43+column44+column45+column46+column47+column48+column27+column28+column29+column30+column31+column32+column33+column34+column35+column36+column37+column38+column39+column40+column19+column20+column21+column22+column23+column24+column25+column26+column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18+column120)/10000 as cost_total2,
+(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18-column18)/10000 as cost_wireless,
+(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115+column4)/10000 as cost_bai,
+(column10+column23+column31+column45+column53+column61+column67+column74+column81+column90+column103+column109+column116+column6+column20+column28+column42+column50+column58+column71+column79+column87+column101+column7+column21+column29+column43+column51+column59+column65+column72+column80+column88+column96+column102+column11+column24+column32+column46+column54+column62+column68+column75+column82+column91+column104+column9)/10000 as cost_fix,
+(column12+column15+column16)/10000 as cost_rental_3rd,
+(column2+column3)/10000 as cost_rental_tower,
+(column119+column114+column107+column98+column93+column84+column77+column69+column64+column56+column48+column40+column26+column18)/10000 as cost_people
+from sqmdb_cost.report49) a
+left join
+--网格数据缺少分母
+(select report_id,smonth,sname,stype,column4 as income_year from sqmdb_cost.report80040) b
+on a.smonth=b.smonth and a.sname=b.sname
+
+
+
+

+ 12 - 0
Scripts/02.sql

@@ -0,0 +1,12 @@
+--02、网运成本占收比(省内口径)
+select 
+smonth,
+stype,
+sname,
+cost_total,
+income,
+cost_total/income as cost_income_rate
+from sqmdb_cost.chengben_shengnei
+--where stype='北10'
+--where stype='地市'
+where smonth='202203'

+ 33 - 0
Scripts/03.sql

@@ -0,0 +1,33 @@
+--03、网运成本预算完成进度(集团口径)
+---北10(顺序:北京 天津 河北 山西 内蒙古 辽宁 吉林 黑龙江 山东 河南)
+select smonth,sname,
+column1 as total_cost,
+column2 as total_ys,
+case when column2=0 then 1 else column1/column2 end as rate_ys
+--case 
+--when sname='北京' then 110000
+--when sname='天津' then 120000
+--when sname='河北' then 130000
+--when sname='山西' then 140000
+--when sname='内蒙古' then 150000
+--when sname='辽宁' then 210000
+--when sname='吉林' then 220000
+--when sname='黑龙江' then 230000
+--when sname='山东' then 370000
+--when sname='河南' then 410000
+--end as prov_code
+from sqmdb_cost.report50002 
+where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202203'
+order by case
+when sname='北京' then 1
+when sname='天津' then 2
+when sname='河北' then 3
+when sname='山西' then 4
+when sname='内蒙古' then 5
+when sname='辽宁' then 6
+when sname='吉林' then 7
+when sname='黑龙江' then 8
+when sname='山东' then 9
+when sname='河南' then 10
+end

+ 32 - 0
Scripts/05.sql

@@ -0,0 +1,32 @@
+--05、百元资产网运成本(集团口径)表九
+---北10
+select 
+'202203' as smonth,
+a.sname,
+--a.stype,
+a.cost_total,b.zichan,
+a.cost_total/b.zichan*100 as cost_bai
+from
+(select sname,sum(column1)/10000 as cost_total from sqmdb_cost.report50 
+where smonth between '202201' and '202203' and stype='分省展现' group by sname) a
+left join
+(select sname,(column7+column8)/2 as zichan from sqmdb_cost.report80054 where smonth='202203') b
+on a.sname=b.sname
+where a.sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+
+
+---地市
+select 
+'202203' as smonth,
+a.sname,
+--a.stype,
+a.cost_total,b.zichan,
+a.cost_total/b.zichan*100 as cost_bai
+from
+(select sname,sum(column1)/10000 as cost_total from sqmdb_cost.report50 
+where smonth between '202201' and '202203' and stype='北方省汇总展现' group by sname) a
+left join
+(select sname,(column7+column8)/2 as zichan from sqmdb_cost.report80054 where smonth='202203') b
+on a.sname=b.sname
+where a.sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+

+ 27 - 0
Scripts/06.sql

@@ -0,0 +1,27 @@
+--06、百元资产网运成本(省内口径)
+---北10
+select a.smonth,a.sname,a.cost_total,b.zichan,
+a.cost_total/b.zichan*100 as cost_bai
+from
+(select smonth,stype,sname,cost_total as cost_total from sqmdb_cost.chengben_shengnei 
+where stype='北10'
+and smonth='202203') a
+join
+(select smonth,sname,stype,(column7+column8)/2 as zichan from sqmdb_cost.report80054
+where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and stype='分省展现'
+and smonth='202203') b
+on a.sname=b.sname
+
+---地市
+select a.smonth,a.sname,a.cost_total,b.zichan,
+a.cost_total/b.zichan*100 as cost_bai
+from
+(select smonth,stype,sname,cost_total from sqmdb_cost.chengben_shengnei 
+where stype='地市'
+and smonth='202203') a
+join
+(select smonth,sname,stype,(column7+column8)/2 as zichan from sqmdb_cost.report80054
+where sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and smonth='202203') b
+on a.sname=b.sname

+ 41 - 0
Scripts/07.sql

@@ -0,0 +1,41 @@
+--07、百元净资产网运成本
+---北10
+select a.smonth,a.sname,
+--a.stype,
+a.zichan,b.zhejiu,
+a.zichan-b.zhejiu as jzc,c.cost_total,
+c.cost_total/(a.zichan-b.zhejiu)*100 as jzc_rate
+from 
+(select '202203' as smonth,sname,stype,sum(column7+column8)/2 as zichan 
+from sqmdb_cost.report80054 where period_type='M' and smonth between '202201' and '202203' group by sname,stype) a
+left join
+(select '202203' as smonth,sname,stype,sum(column16) as zhejiu 
+from sqmdb_cost.report80053 where period_type='M' and smonth between '202201' and '202203' group by sname,stype) b
+on a.smonth=b.smonth and a.sname=b.sname and a.stype=b.stype
+left join
+(select '202203' as smonth,sname,stype,sum(column1)/10000 as cost_total 
+from sqmdb_cost.report50 where smonth between '202201' and '202203' group by sname,stype) c
+on a.smonth=c.smonth and a.sname=c.sname and a.stype=c.stype
+where a.sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+
+
+
+---地市
+select a.smonth,a.sname,
+--a.stype,
+a.zichan,b.zhejiu,
+a.zichan-b.zhejiu as jzc,c.cost_total,
+c.cost_total/(a.zichan-b.zhejiu)*100 as jzc_rate
+from 
+(select '202203' as smonth,sname,stype,sum(column7+column8)/2 as zichan 
+from sqmdb_cost.report80054 where period_type='M' and smonth between '202201' and '202203' group by sname,stype) a
+left join
+(select '202203' as smonth,sname,stype,sum(column16) as zhejiu 
+from sqmdb_cost.report80053 where period_type='M' and smonth between '202201' and '202203' group by sname,stype) b
+on a.smonth=b.smonth and a.sname=b.sname and a.stype=b.stype
+left join
+(select '202203' as smonth,sname,stype,sum(column1)/10000 as cost_total 
+from sqmdb_cost.report50 where smonth between '202201' and '202203' group by sname,stype) c
+on a.smonth=c.smonth and a.sname=c.sname
+where a.sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+

+ 39 - 0
Scripts/08.sql

@@ -0,0 +1,39 @@
+--08、网络能耗占收比
+---北10
+select 
+smonth as 月份,
+sname as 省份,
+column1 as 能耗成本,
+column5 as 本年收入累计,
+column8 as 百元收入网络能耗,
+column1/column5 as 网络能耗占收比
+from sqmdb_cost.report50010 
+where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202203'
+
+
+---地市
+select 
+a.smonth as 月份,
+a.sname as 公司,
+--a.stype as 数据类型,
+a.cost_nenghao as 网络能耗,
+b.income_year as 本年收入累计,
+case when b.income_year=0 then null else a.cost_nenghao/b.income_year*100 end as 百元收入网络能耗,
+case when b.income_year=0 then null else a.cost_nenghao/b.income_year end as 网络能耗占收比
+from
+(select '202203' as smonth,sname,stype,
+sum(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115)/10000 as cost_nenghao
+from sqmdb_cost.report50 where stype ='北方省汇总展现' and smonth between '202201' and '202203' group by sname,stype) a
+left join
+(select report_id,smonth,sname,stype,column4 as income_year from sqmdb_cost.report80040) b
+on a.smonth=b.smonth and a.sname=b.sname
+where 
+a.sname in ('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+
+
+
+---网格(网格数据缺少分母)-目前只有分子
+select smonth,segment1_name,city_name,grid_name,
+(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115+column4)/10000 as cost_nenghao
+from sqmdb_cost.report49

+ 24 - 0
Scripts/09.sql

@@ -0,0 +1,24 @@
+--09、百元资产修理维护费
+---北10
+select t1.smonth,t1.sname,t1.cost_fix,t2.zichan,
+(t1.cost_fix/t2.zichan)*100 as cost_bai_fix
+from
+(select smonth,stype,sname,cost_fix from sqmdb_cost.chengben_shengnei where smonth='202203' and stype='北10') t1
+join
+(select smonth,sname,stype,(column7+column8)/2 as zichan from sqmdb_cost.report80054 where period_type='M'
+and sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and stype='分省展现'
+and smonth='202203') t2
+on t1.sname=t2.sname
+
+
+---地市
+select t1.smonth,t1.sname,t1.cost_fix,t2.zichan,
+(t1.cost_fix/t2.zichan)*100 as cost_bai_fix
+from
+(select smonth,stype,sname,cost_fix from sqmdb_cost.chengben_shengnei where smonth='202203' and stype='地市') t1
+join
+(select smonth,sname,stype,(column7+column8)/2 as zichan from sqmdb_cost.report80054 where period_type='M'
+and sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and smonth='202203') t2
+on t1.sname=t2.sname

+ 12 - 0
Scripts/10.sql

@@ -0,0 +1,12 @@
+--10、修理维护费占收比(省内口径)
+select 
+smonth,
+stype,
+sname,
+cost_fix,
+income,
+cost_fix/income as cost_fix_rate
+from sqmdb_cost.chengben_shengnei
+where smonth='202203'
+--where stype='北10'
+--where stype='地市'

+ 53 - 0
Scripts/11.sql

@@ -0,0 +1,53 @@
+--11、单业务量移网成本
+---地市
+select cost_t.smonth,cost_t.city_name,cost_t.cost_yw,cost_t.cost_hexin,ywl_t.yewul,
+(cost_t.cost_yw+cost_t.cost_hexin)/ywl_t.yewul as cost_ywl
+from 
+(select a.smonth,dg.city_name,a.cost_yw,a.cost_hexin from
+(select '202203' as smonth,sname,
+sum(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18) as cost_yw,
+sum(column19+column20+column21+column22+column23+column24+column25+column26) as cost_hexin
+from sqmdb_cost.report50
+where period_type='M' 
+and sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and smonth between '202201' and '202203' group by sname) a
+join (select distinct city_pro,city_name from sqmdb_cost.dict_grid) dg 
+on a.sname=dg.city_pro) cost_t
+join
+(select dg.city_name,(y1.yewul+y2.yewul)/2 as yewul from
+(select city_name,sum(yewul) as yewul from sqmdb_cost.zpzs z where grid_name!='合计' and smonth='202112' group by city_name) y1
+join
+(select city_name,sum(yewul) as yewul from sqmdb_cost.zpzs z where grid_name!='合计' and smonth='202203' group by city_name) y2
+on y1.city_name=y2.city_name
+join 
+(select distinct city_sname,city_name from sqmdb_cost.dict_grid) dg
+on y1.city_name=dg.city_sname) ywl_t
+on cost_t.city_name=ywl_t.city_name
+
+
+
+---网格
+select cost_t.smonth,cost_t.city_name,cost_t.area_name,cost_t.cost_yw,cost_t.cost_hexin,ywl_t.yewul,
+(cost_t.cost_yw+cost_t.cost_hexin)/ywl_t.yewul as cost_ywl
+from 
+(select a.smonth,dg.city_name,dg.area_name,a.cost_yw,a.cost_hexin from
+(select smonth,city_code,city_name,grid_code,grid_name,
+(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18) as cost_yw,
+(column19+column20+column21+column22+column23+column24+column25+column26) as cost_hexin
+from sqmdb_cost.report49
+where period_type='Y' 
+and smonth='202203') a 
+join sqmdb_cost.dict_grid dg 
+on a.city_code=dg.grid_city_code::varchar and a.grid_code=dg.grid_code::varchar) cost_t
+join
+(select dg.city_name,dg.area_name,(y1.yewul+y2.yewul)/2 as yewul from
+(select city_name,grid_name,sum(yewul) as yewul from sqmdb_cost.zpzs z where grid_name!='合计' and smonth='202112' group by city_name,grid_name) y1
+join
+(select city_name,grid_name,sum(yewul) as yewul from sqmdb_cost.zpzs z where grid_name!='合计' and smonth='202203' group by city_name,grid_name) y2
+on y1.city_name=y2.city_name and y1.grid_name=y2.grid_name
+join 
+(select distinct city_sname,city_name,area_name,grid_name from sqmdb_cost.dict_grid) dg
+on y1.city_name=dg.city_sname and y1.grid_name=dg.grid_name) ywl_t
+on cost_t.city_name=ywl_t.city_name and cost_t.area_name=ywl_t.area_name
+
+

+ 78 - 0
Scripts/12_13.sql

@@ -0,0 +1,78 @@
+--端口数
+select local_net_name,area_name,sum(ftth_port_count) as ftth_port_count
+from sqmdb_cost.kuandai_ftth
+where sdate='2022-04-02 00:00:00'
+group by local_net_name,area_name 
+
+select sdate,local_net_name,area_name,areal_type_name,ftth_port_count
+from sqmdb_cost.kuandai_ftth where local_net_name ='石家庄' and area_name='平山'
+
+--12、单端口网运成本(月)
+--13、单端口能耗成本(月)
+--全省
+--create table sqmdb_cost.rpt_dport_cost_prov as
+select 
+t1.smonth,t1.sname,t1.cost_total,t1.cost_nenghao,t2.port_inuse,
+t1.cost_total/t2.port_inuse/3 as cost_port,
+t1.cost_nenghao/t2.port_inuse/3 as cost_port_nenghao
+from 
+(select '202203' as smonth,sname,stype,
+sum(column1-column2-column3-column4-column5-column6-column7-column8-column9-column10-column11-column12-column13-column14-column15-column16-column17-column18-column19-column20-column21-column22-column23-column24-column25-column26-column108-column109-column110-column111-column112-column113-column114)/10000 as cost_total,
+sum(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115-column5-column19-column108)/10000 as cost_nenghao
+from sqmdb_cost.report50 r
+where period_type='M' and sname='河北'
+and smonth between '202201' and '202203' group by sname,stype) t1
+join
+(select sname,port_inuse from sqmdb_cost.jt_number_b10 where sname='河北' and smonth='202203') t2
+on t1.sname=t2.sname
+
+
+
+---地市
+--create table sqmdb_cost.rpt_dport_cost_city as
+select t1.smonth,t1.city_sname,t1.cost_total,t1.cost_nenghao,t2.port_inuse,
+t1.cost_total/t2.port_inuse/4 as cost_port,
+t1.cost_nenghao/t2.port_inuse/4 as cost_port_nenghao
+from 
+(select a.smonth,dg.city_sname,a.cost_total,a.cost_nenghao from
+(select '202204' as smonth,sname,stype,
+sum(column1-column2-column3-column4-column5-column6-column7-column8-column9-column10-column11-column12-column13-column14-column15-column16-column17-column18-column19-column20-column21-column22-column23-column24-column25-column26-column108-column109-column110-column111-column112-column113-column114)/10000 as cost_total,
+sum(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115-column5-column19-column108)/10000 as cost_nenghao
+from sqmdb_cost.report50 r
+where stype ='北方省汇总展现'
+and period_type='M'
+and sname in ('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and smonth between '202201' and '202204' group by sname,stype) a
+join 
+(select distinct city_sname,city_pro from sqmdb_cost.dict_grid) dg
+on a.sname=dg.city_pro) t1
+join
+(select city_name,port_inuse from sqmdb_cost.jt_number_city where month_id='202204') t2
+on t1.city_sname=t2.city_name
+
+
+
+--单端口能耗、网运成本--网格
+--create table sqmdb_cost.rpt_dport_cost_grid_1 as
+select t1.smonth,dcg.city_name,dcg.grid_name,t1.cost_total,t1.cost_nenghao,t2.ftth_port_sts_count,
+t1.cost_total/t2.ftth_port_sts_count/4 as cost_port,
+t1.cost_nenghao/t2.ftth_port_sts_count/4 as cost_port_nenghao,
+dcg.city_code,dcg.area_code
+from 
+(select jt.smonth,jt.cost_total,jt.cost_nenghao,dgc.grid_code from
+(select smonth,period_type,segment1_name,city_code,city_name_short(city_name) as city_name,grid_code,grid_name,
+(column1-column2-column3-column4-column5-column6-column7-column8-column9-column10-column11-column12-column13-column14-column15-column16-column17-column18-column19-column20-column21-column22-column23-column24-column25-column26-column108-column109-column110-column111-column112-column113-column114)/10000 as cost_total,
+(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115-column5-column19-column108)/10000 as cost_nenghao
+from sqmdb_cost.report49
+where period_type='Y' and grid_name!='合计' and smonth='202204') jt
+left join sqmdb_cost.dict_grid_code dgc on jt.city_name=dgc.city_name and trim(jt.grid_name)=trim(dgc.grid_name)
+where dgc.grid_code is not null) t1
+join
+(select a.ftth_port_sts_count,dgc1.grid_code from 
+(select sdate,city_name_short(local_net_name) as city_name,area_name,sum(ftth_port_sts_count)/10000 as ftth_port_sts_count
+from sqmdb_cost.kuandai_ftth 
+where areal_type_name!='小计' and sdate='2022-04-30 00:00:00'
+group by sdate,city_name_short(local_net_name),area_name) a
+left join sqmdb_cost.dict_grid_code dgc1 on a.city_name=dgc1.city_name and trim(a.area_name)=trim(dgc1.grid_name)) t2
+on t1.grid_code=t2.grid_code
+left join sqmdb_cost.dict_code_grid dcg on t1.grid_code=dcg.grid_code

+ 114 - 0
Scripts/14.sql

@@ -0,0 +1,114 @@
+--14、单载频载扇能耗(月)
+---北10
+--create table sqmdb_cost.rpt_dzpzs_cost_b10 as 
+select fz.smonth,fz.sname,fz.cost_yw,fz.cost_hexin,
+(fz.cost_yw+fz.cost_hexin) as cost_total,
+fm.zps_num_no5g,
+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,
+case 
+when fz.sname='北京' then 110000
+when fz.sname='天津' then 120000
+when fz.sname='河北' then 130000
+when fz.sname='山西' then 140000
+when fz.sname='内蒙古' then 150000
+when fz.sname='辽宁' then 210000
+when fz.sname='吉林' then 220000
+when fz.sname='黑龙江' then 230000
+when fz.sname='山东' then 370000
+when fz.sname='河南' then 410000
+end as prov_code 
+from
+(select '202203' as smonth,sname,
+sum(column4+column5)/10000 as cost_yw,
+sum(column19)/10000 as cost_hexin
+from sqmdb_cost.report50
+where period_type='M' 
+and sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth between '202201' and '202203' group by sname) fz
+join
+(select smonth,sname,zps_total_no5g as zps_num_no5g 
+from sqmdb_cost.jt_number_b10 where smonth='202203') fm
+on fz.sname=fm.sname
+
+
+--全省
+select fz.smonth,fz.sname,fz.cost_yw,fz.cost_hexin,
+(fz.cost_yw+fz.cost_hexin) as cost_total,
+fm.zps_num_with5g,
+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
+from
+(select '202204' as smonth,sname,
+sum(column4+column5)/10000 as cost_yw,
+sum(column19)/10000 as cost_hexin
+from sqmdb_cost.report50
+where period_type='M' and sname ='河北' and smonth between '202201' and '202204' group by sname) fz
+join
+(select a.city_name,(a.zps_total+b.zps_total)/10000/2 as zps_num_with5g from
+(select '河北' as city_name,zps_total from sqmdb_cost.zpzs_city where smonth='202112' and city_name='全省')a
+join
+(select '河北' as city_name,zps_total from sqmdb_cost.zpzs_city where smonth='202204' and city_name='全省')b
+on a.city_name=b.city_name) fm
+on fz.sname=fm.city_name
+
+
+
+---地市
+select fz.smonth,fz.city_sname,fz.cost_yw,fz.cost_hexin,
+(fz.cost_yw+fz.cost_hexin) as cost_total,
+fm.zps_num_with5g,
+fm.zps_num_no5g,
+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,
+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,
+fz.city_code*100 as city_code
+from
+(select a.smonth,dg.city_sname,dg.city_code,a.cost_yw,a.cost_hexin from
+(select '202204' as smonth,sname,
+sum(column4+column5)/10000 as cost_yw,
+sum(column19)/10000 as cost_hexin
+from sqmdb_cost.report50
+where period_type='M' 
+and sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and smonth between '202201' and '202204' group by sname) a
+join (select distinct city_code,city_sname,city_pro from sqmdb_cost.dict_grid) dg 
+on a.sname=dg.city_pro) fz
+join
+(select 
+city_name,
+zps_total_with5g as zps_num_with5g,
+zps_total_no5g as zps_num_no5g 
+from sqmdb_cost.jt_number_city where month_id='202204') fm
+on fz.city_sname=fm.city_name
+order by fz.city_code
+
+
+--单载频载扇能耗--网格
+--create table sqmdb_cost.rpt_dzpzs_cost_grid_1 as
+select fm.smonth,dcg.city_name,dcg.grid_name,fz.cost_yw,fz.cost_hexin,
+(fz.cost_yw+fz.cost_hexin) as cost_total,
+fm.zps_num_with5g,
+fm.zps_num_no5g,
+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,
+null cost_zps_no5g,
+dcg.city_code,dcg.area_code
+from
+(select jt.smonth,jt.city_name,jt.grid_name,jt.cost_yw,jt.cost_hexin,dgc.grid_code from 
+(select smonth,city_name_short(city_name) as city_name,grid_name,(column4+column5) as cost_yw,column19 as cost_hexin
+from sqmdb_cost.report49 where period_type='Y' and smonth='202204')jt
+left join sqmdb_cost.dict_grid_code dgc on jt.city_name=dgc.city_name and trim(jt.grid_name)=trim(dgc.grid_name)
+where dgc.grid_code is not null) fz
+join
+(select z1.smonth,z1.city_name as city_name,z1.grid_name,
+z2.zps_num_total as zps_num_total_ly,
+z1.zps_num_total as zps_num_total_cm,
+avg_num(z1.zps_num_total,z2.zps_num_total) as zps_num_with5g,
+null as zps_num_no5g,
+dgc1.grid_code 
+from
+(select * from sqmdb_cost.zpzs where smonth='202204') z1
+ join
+(select * from sqmdb_cost.zpzs where smonth='202112') z2
+on trim(z1.city_name)=trim(z2.city_name) and trim(z1.grid_name)=trim(z2.grid_name)
+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)
+where dgc1.grid_code is not null) fm
+on fz.grid_code=fm.grid_code
+left join sqmdb_cost.dict_code_grid dcg on fz.grid_code=dcg.grid_code 

+ 21 - 0
Scripts/15.sql

@@ -0,0 +1,21 @@
+--15、活动ONU单端口能耗(月)
+---地市
+select 
+t1.smonth,
+t1.city_name,
+t1.cost_nenghao/10000 as cost_nenghao,
+t2.active_onu_num/10000 as active_onu_num,
+t1.cost_nenghao/t2.active_onu_num as cost_onu
+from 
+(select distinct a.smonth,dg.city_name,a.cost_nenghao from
+(select smonth,sname,stype,
+(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115)-column5-column19-column108 as cost_nenghao
+from sqmdb_cost.report50 r
+where stype ='北方省汇总展现'
+and sname in ('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and smonth='202203') a
+join sqmdb_cost.dict_grid dg
+on a.sname=dg.city_pro) t1
+join
+(select * from sqmdb_cost.active_onu) t2
+on t1.city_name=t2.city_name

+ 151 - 0
Scripts/16.sql

@@ -0,0 +1,151 @@
+--16、单站铁塔租赁费(月)
+---北10数据(select * from sqmdb_cost.report50016)
+select 
+smonth as MONTH_ID,
+'北10' as ZB_TYPE,
+sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'16' as ZB_CODE,
+'单站铁塔租赁费(月)' as ZB_NAME,
+column2*10000 as QZ_FZ,
+column5 as QZ_FM,
+column2*10000/column5/4 as BY_QZ
+from sqmdb_cost.report50016
+where sname in ('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202204'
+
+--北10
+select 
+smonth,
+sname,
+column2*10000 as tower_cost,
+column4 as tower_num_ly,
+column3 as tower_num_cm,
+(column3+column4)/2 as tower_num_avg,
+column2*10000/((column3+column4)/2)/4 as tower_cost_avg
+from sqmdb_cost.report50016 
+where sname in ('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202204'
+
+--河北省
+select smonth,sname,column1 as tower_cost_avg_prov from sqmdb_cost.report50016 where smonth='202204' and sname='河北'
+
+
+---地市
+--create table sqmdb_cost.rpt_tower_cost_city as 
+select 
+'202204' as smonth,
+(regexp_split_to_array(tc.sname,'_'))[1] as city_name,
+tc.tower_cost,
+tn.tower_num_ly,
+tn.tower_num_cm,
+tn.tower_num_avg,
+(tc.tower_cost/tn.tower_num_avg)/4 as tower_cost_avg
+from
+(select sname,sum(column2+column3) as tower_cost from sqmdb_cost.report50 r 
+where period_type='M' and smonth between '202201' and '202204' group by sname)tc
+join
+(with tower_code as (select distinct sdate,city_operator,site_addr_id from sqmdb_cost.tower3 where stype!='室分'
+union all
+select sdate,city_operator,site_addr_id from sqmdb_cost.tower3 where stype='室分')
+select 
+dg.city_code,
+dg.city_pro,
+t1.tower_num_ly,
+t2.tower_num_cm,
+(t1.tower_num_ly+t2.tower_num_cm)/2 as tower_num_avg
+from
+(select city_operator,count(*) as tower_num_ly from tower_code where sdate='202112' group by city_operator)t1
+join 
+(select city_operator,count(*) as tower_num_cm from tower_code where sdate='202204' group by city_operator)t2
+on t1.city_operator=t2.city_operator
+join
+(select distinct city_code,city_name,city_pro from sqmdb_cost.dict_grid)dg
+on t1.city_operator=dg.city_name) tn
+on tc.sname=tn.city_pro
+
+
+---网格---网格名称+区县名称
+--drop table sqmdb_cost.rpt_tower_cost_grid
+--create table sqmdb_cost.rpt_tower_cost_grid as 
+select 
+tc.smonth,
+(regexp_split_to_array(tc.city_name,'_'))[2] as city_name,
+tn.area_name,
+tn.area_tower,
+tc.grid_name,
+tc.tower_cost,
+tn.tower_num_ly,
+tn.tower_num_cm,
+tn.tower_num_avg,
+(tc.tower_cost/tn.tower_num_avg)/4 as tower_cost_avg
+from
+(select smonth,city_name,grid_name,(column2+column3) as tower_cost from sqmdb_cost.report49 r 
+where period_type='Y' and smonth='202204')tc
+join
+(with tower_code as (
+select distinct sdate,city_operator,area_operator,site_addr_id from sqmdb_cost.tower3 where stype!='室分'
+union all
+select sdate,city_operator,area_operator,site_addr_id from sqmdb_cost.tower3 where stype='室分')
+select 
+dg.city_code,
+dg.area_name,
+dg.area_tower,
+dg.grid_city_name,
+dg.grid_name,
+t1.area_operator,
+t1.tower_num_ly,
+t2.tower_num_cm,
+(t1.tower_num_ly+t2.tower_num_cm)/2 as tower_num_avg
+from
+(select city_operator,area_operator,count(*) as tower_num_ly from tower_code where sdate='202112' group by city_operator,area_operator)t1
+join 
+(select city_operator,area_operator,count(*) as tower_num_cm from tower_code where sdate='202204' group by city_operator,area_operator)t2
+on t1.city_operator=t2.city_operator and t1.area_operator=t2.area_operator
+join
+(select distinct city_code,city_name,area_name,grid_city_name,grid_name,area_tower from sqmdb_cost.dict_grid)dg
+on t1.city_operator=dg.city_name and t1.area_operator=dg.area_tower) tn
+on tc.city_name=tn.grid_city_name and trim(tc.grid_name)=trim(tn.grid_name)
+
+
+
+---网格---使用铁塔预提表计算网格站点数
+--drop table sqmdb_cost.rpt_tower_cost_grid_1
+--create table sqmdb_cost.rpt_tower_cost_grid_1 as 
+select 
+tc.smonth,
+tc.city_name,
+dcg.city_code*100 as city_code,
+dcg.grid_name,
+dcg.grid_code,
+--tn.area_name,
+--tn.area_tower,
+--tc.grid_name,
+tc.tower_cost,
+tn.tower_num_ly,
+tn.tower_num_cm,
+tn.tower_num_avg,
+(tc.tower_cost/tn.tower_num_avg)/4 as tower_cost_avg
+from
+(select t1.smonth,t1.city_name,t1.tower_cost,t2.grid_code 
+from 
+(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
+left join sqmdb_cost.dict_grid_code t2 on t1.city_name=t2.city_name and trim(t1.grid_name)=trim(t2.grid_name) 
+where t2.grid_code is not null)tc
+join
+(select yt.city_name,dgc.grid_code,yt.tower_num_ly,yt.tower_num_cm,yt.tower_num_avg from
+(select a.city_name,a.cbzx,b.tower_num_ly,a.tower_num_cm,
+avg_num(a.tower_num_cm,b.tower_num_ly) as tower_num_avg
+from 
+(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
+join
+(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
+on a.city_name=b.city_name and a.cbzx=b.cbzx) yt
+left join sqmdb_cost.dict_grid_code dgc on yt.city_name=dgc.city_name and trim(yt.cbzx)=trim(dgc.grid_name)) tn
+on tc.grid_code=tn.grid_code
+left join sqmdb_cost.dict_code_grid dcg on tc.grid_code=dcg.grid_code
+
+

+ 16 - 0
Scripts/17.sql

@@ -0,0 +1,16 @@
+--17、户均装机料费
+---地市
+select fz.smonth,fz.sname,fz.cost_liao,fm.order_num,
+fz.cost_liao/fm.order_num as cost_order
+from
+(select smonth,sname,cost_liao from sqmdb_cost.chengben_shengnei cs
+where stype='地市' and smonth='202203') fz
+join
+(select b.city_code,b.city_pro,a.order_num from
+(select smonth,city_code,city_name,sum(order_num)/10000 as order_num 
+from sqmdb_cost.zhuangji z where smonth='202203'
+group by smonth,city_code,city_name) a
+join
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid dg) b
+on a.city_code=b.city_code) fm
+on fz.sname=fm.city_pro

+ 34 - 0
Scripts/18.sql

@@ -0,0 +1,34 @@
+--18、单皮长公里线路维护费(月)
+---北10(只有分子)
+select smonth,sname,
+(column65+column66+column67+column68+column69) as cost_xianlu
+from sqmdb_cost.report50
+where sname in ('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202203'
+
+
+---地市
+select t1.smonth,t1.sname,t1.cost_xianlu,t2.total_gl, 
+t1.cost_xianlu/t2.total_gl/3 as cost_gl
+from
+(select '202203' as smonth,sname,
+sum(column65+column66+column67+column68+column69)/10000 as cost_xianlu
+from sqmdb_cost.report50
+where sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and smonth between '202201' and '202203' group by sname) t1
+join
+(select 
+case when city_name='雄安新区' then '雄安_河北' else city_name||'_河北' end as city_pro,
+total_gl 
+from sqmdb_cost.jt_number_city where month_id='202203') t2
+on t1.sname=t2.city_pro
+
+
+---网格(只有分子)
+select a.smonth,dg.city_name,dg.area_name,a.cost_xianlu from
+(select smonth,city_code,city_name,grid_code,grid_name,
+(column65+column66+column67+column68+column69) as cost_xianlu
+from sqmdb_cost.report49
+where period_type='M' and prov_name='河北' and smonth='202203') a 
+join sqmdb_cost.dict_grid dg 
+on a.city_code=dg.grid_city_code::varchar and a.grid_code=dg.grid_code::varchar

+ 37 - 0
Scripts/19.sql

@@ -0,0 +1,37 @@
+--19、无线成本占收比
+---北10
+select 
+a.smonth as 月份,
+a.sname as 公司,
+--a.stype as 数据类型,
+a.cost_wireless as 无线网成本,
+b.income_year as 本年收入累计,
+case when b.income_year=0 then null else a.cost_wireless/b.income_year end as 无线成本占收比
+from
+(select '202203' as smonth,sname,stype,
+sum(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17)/10000 as cost_wireless --column18 账面人工成本
+from sqmdb_cost.report50 where smonth between '202201' and '202203' group by sname,stype) a
+left join
+(select report_id,smonth,sname,stype,column4 as income_year from sqmdb_cost.report80040) b
+on a.smonth=b.smonth and a.sname=b.sname
+where a.sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and a.smonth='202203'
+
+
+---地市
+select 
+a.smonth as 月份,
+a.sname as 公司,
+--a.stype as 数据类型,
+a.cost_wireless as 无线网成本,
+b.income_year as 本年收入累计,
+case when b.income_year=0 then null else a.cost_wireless/b.income_year end as 无线成本占收比
+from
+(select '202203' as smonth,sname,
+sum(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17)/10000 as cost_wireless --column18 账面人工成本
+from sqmdb_cost.report50 where stype ='北方省汇总展现' and smonth between '202201' and '202203' group by sname) a
+left join
+(select report_id,smonth,sname,stype,column4 as income_year from sqmdb_cost.report80040) b
+on a.smonth=b.smonth and a.sname=b.sname
+where a.sname in ('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and a.smonth='202203'

+ 20 - 0
Scripts/20.sql

@@ -0,0 +1,20 @@
+--20¡¢PUE³¬±êÂÊ
+---µØÊÐ
+select
+city_name,
+count(*) as pue_total,
+sum(case when pue>1.5 then 1 else 0 end) as pue_over,
+sum(case when pue>1.5 then 1 else 0 end)/count(*)::numeric as pue_over_rate
+from sqmdb_cost.pue_top 
+group by city_name
+
+
+---Íø¸ñ
+select 
+city_name,
+area_name,
+count(*) as pue_total,
+sum(case when pue>1.5 then 1 else 0 end) as pue_over,
+sum(case when pue>1.5 then 1 else 0 end)/count(*)::numeric as pue_over_rate
+from sqmdb_cost.pue_top 
+group by city_name,area_name

+ 22 - 0
Scripts/21.sql

@@ -0,0 +1,22 @@
+--21、转供电占比
+---地市(可由网格数据汇聚)
+select
+smonth,
+city_name,
+count(*) as total_num,
+sum(case when y.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end) as zgd_num,
+sum(case when y.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end)/count(*)::numeric as zgd_rate
+from sqmdb_cost.ytmx_new y 
+group by smonth,city_name
+
+
+---网格
+select 
+smonth,
+city_name,
+area_name,
+count(*) as total_num,
+sum(case when y.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end) as zgd_num,
+sum(case when y.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end)/count(*)::numeric as zgd_rate
+from sqmdb_cost.ytmx_new y 
+group by smonth,city_name,area_name

+ 25 - 0
Scripts/22.sql

@@ -0,0 +1,25 @@
+--22、超高电价占比
+---地市(可由网格数据汇聚)
+select
+smonth,
+city_name,
+count(*) as total_num,
+sum(case when y.eprice>0.8 then 1 else 0 end) as high_price_num,
+sum(case when y.eprice>0.8 then 1 else 0 end)/count(*)::numeric as high_price_rate
+from 
+(select *,(case when accrued_power=0 then 0 else accrued_cost/accrued_power end) as eprice from sqmdb_cost.ytmx_new) y 
+group by smonth,city_name
+
+
+
+---网格
+select
+smonth,
+city_name,
+area_name,
+count(*) as total_num,
+sum(case when y.eprice>0.8 then 1 else 0 end) as high_price_num,
+sum(case when y.eprice>0.8 then 1 else 0 end)/count(*)::numeric as high_price_rate
+from 
+(select *,(case when accrued_power=0 then 0 else accrued_cost/accrued_power end) as eprice from sqmdb_cost.ytmx_new) y
+group by smonth,city_name,area_name

+ 30 - 0
Scripts/23.sql

@@ -0,0 +1,30 @@
+--23、铁塔共享率  select * from sqmdb_cost.tower2 
+---地市
+with t as (select distinct sdate,city_operator,area_operator,site_addr_id,is_duxiang from sqmdb_cost.tower3 where stype in ('新建及共享改造','存量注入'))
+select 
+sdate,
+city_operator,
+sum(case when is_duxiang='共享' then 1 else 0 end) as share_num,
+count(*) as total_num,
+sum(case when is_duxiang='共享' then 1 else 0 end)/count(*)::numeric as share_rate
+from t
+where sdate='202204'
+group by sdate,city_operator
+
+
+---网格
+with t as (select distinct sdate,city_operator,area_operator,site_addr_id,is_duxiang from sqmdb_cost.tower3 where stype in ('新建及共享改造','存量注入'))
+select 
+sdate,
+city_operator,
+area_operator,
+sum(case when is_duxiang='共享' then 1 else 0 end) as share_num,
+count(*) as total_num,
+sum(case when is_duxiang='共享' then 1 else 0 end)/count(*)::numeric as share_rate
+from t
+where sdate='202204'
+group by sdate,city_operator,area_operator
+
+
+
+

+ 49 - 0
Scripts/24.sql

@@ -0,0 +1,49 @@
+--24、租赁局站占比
+------------------------使用station3------------------------
+---地市
+select 
+city_name,
+count(*) as total_num,
+sum(case when property_type like '%租用%' then 1 else 0 end) as zu_num,
+sum(case when property_type like '%租用%' then 1 else 0 end)/count(*)::numeric as zu_rate
+from sqmdb_cost.station3
+group by city_name
+order by city_name
+
+---网格
+select 
+city_name,area_name,
+count(*) as total_num,
+sum(case when property_type like '%租用%' then 1 else 0 end) as zu_num,
+sum(case when property_type like '%租用%' then 1 else 0 end)/count(*)::numeric as zu_rate
+from sqmdb_cost.station3
+group by city_name,area_name
+order by city_name,area_name
+
+------------------------使用station2------------------------
+--select * from sqmdb_cost.dict where dicttext like '%租用%'(99928:租用铁塔,99931:租用第三方)
+---地市
+select 
+c.dicttext as city_name,
+a.zuyong::numeric/b.total::numeric as zu_rate
+from 
+(select city_code,count(*) as zuyong from sqmdb_cost.station2 where property_type in ('99928','99931') group by city_code) a
+left join
+(select city_code,count(*) as total from sqmdb_cost.station2 group by city_code) b
+on a.city_code=b.city_code
+left join sqmdb_cost.dict c on a.city_code::varchar=c.dictid
+order by c.dicttext
+
+---网格
+select 
+c.dicttext as city_name,
+d.dicttext as area_name,
+a.zuyong::numeric/b.total::numeric as zu_rate
+from 
+(select city_code,area_code,count(*) as zuyong from sqmdb_cost.station2 where property_type in ('99928','99931') group by city_code,area_code) a
+left join
+(select city_code,area_code,count(*) as total from sqmdb_cost.station2 group by city_code,area_code) b
+on a.city_code=b.city_code and a.area_code=b.area_code
+left join sqmdb_cost.dict c on a.city_code::varchar=c.dictid
+left join sqmdb_cost.dict d on a.area_code::varchar=d.dictid
+order by c.dicttext,d.dicttext

+ 56 - 0
Scripts/25.sql

@@ -0,0 +1,56 @@
+--25、샘籃데籃頓契냥굶槻樓
+---뒈懇
+select t1.smonth,t1.sname,t1.cost_wuxian,
+t1.cost_hexin,t1.cost_wuxian_hexin,t2.site_count,
+t1.cost_wuxian_hexin/t2.site_count as site_cost
+from 
+(select smonth,sname,stype,
+(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18) as cost_wuxian,
+(column19+column20+column21+column22+column23+column24+column25+column26) as cost_hexin,
+(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18+column19+column20+column21+column22+column23+column24+column25+column26) as cost_wuxian_hexin
+from sqmdb_cost.report50
+where sname in('柯소鏤_붉굇','鉗�_붉굇','해뽈돎_붉굇','벳덱_붉굇','饉憩_붉굇','괏땍_붉굇','蠟소왯_붉굇','넓돠_붉굇','읜렌_붉굇','꾕鹵_붉굇','뷜彊_붉굇','衿갛_붉굇')
+and smonth='202203') t1
+left join
+(select city_code,
+case when city_code=1301 then '柯소鏤_붉굇'
+when city_code=1302 then '鉗�_붉굇'
+when city_code=1303 then '해뽈돎_붉굇'
+when city_code=1304 then '벳덱_붉굇'
+when city_code=1305 then '饉憩_붉굇'
+when city_code=1306 then '괏땍_붉굇'
+when city_code=1307 then '蠟소왯_붉굇'
+when city_code=1308 then '넓돠_붉굇'
+when city_code=1309 then '꾕鹵_붉굇'
+when city_code=1310 then '읜렌_붉굇'
+when city_code=1311 then '뷜彊_붉굇'
+when city_code=1312 then '衿갛_붉굇'
+else '' end as city_name,
+count(*) as site_count
+from (select distinct eqp_sid,city_code from sqmdb_cost.equip where profession ='盧땡轟窟') a
+group by city_code) t2
+on t1.sname=t2.city_name
+
+---貢목
+select t1.city_name,t1.area_name,t1.cost_wuxian,t1.cost_hexin,t1.cost_wuxian_hexin,t2.site_count,
+t1.cost_wuxian_hexin/t2.site_count as site_cost
+from
+(select fz.smonth,dg.city_name,dg.area_name,fz.cost_wuxian,fz.cost_hexin,fz.cost_wuxian_hexin from 
+(select smonth,period_type,segment1_name,city_code,city_name,grid_code,grid_name,
+(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18) as cost_wuxian,
+(column19+column20+column21+column22+column23+column24+column25+column26) as cost_hexin,
+(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18+column19+column20+column21+column22+column23+column24+column25+column26) as cost_wuxian_hexin
+from sqmdb_cost.report49
+--where sname in('붉굇伽굶꼬','柯소鏤_붉굇','鉗�_붉굇','해뽈돎_붉굇','벳덱_붉굇','饉憩_붉굇','괏땍_붉굇','蠟소왯_붉굇','넓돠_붉굇','읜렌_붉굇','꾕鹵_붉굇','뷜彊_붉굇','衿갛_붉굇')
+where period_type='M' and grid_name!='북셕' and smonth='202203') fz
+join sqmdb_cost.dict_grid dg
+on fz.city_code=dg.grid_city_code::varchar and fz.grid_code=dg.grid_code::varchar) t1
+join
+(select dg.city_name,dg.area_name,sc.site_count from
+(select city_code,area_code,count(*) as site_count from 
+(select distinct eqp_sid,city_code,area_code from sqmdb_cost.equip where profession ='盧땡轟窟') et
+group by city_code,area_code) sc
+join sqmdb_cost.dict_grid dg
+on sc.city_code=dg.city_code and sc.area_code=dg.area_code) t2
+on t1.city_name=t2.city_name and t1.area_name=t2.area_name
+order by t1.city_name,t1.area_name

+ 30 - 0
Scripts/26.sql

@@ -0,0 +1,30 @@
+--26、H端口实占率
+---地市新版(使用baobiao_ipduankou整理)
+select month_id,city_name,port_total,port_inuse,port_rate 
+from sqmdb_cost.jt_number_city jnc where month_id='202203'
+
+---地市旧版,使用kuandai_ftth(率值:ftth_port_sts_count/ftth_port_count)
+select local_net_name,
+sum(ftth_port_count)/10000 as ftth_port_count,
+sum(ftth_port_sts_count)/10000 as ftth_port_sts_count,
+sum(ftth_port_sts_count)/sum(ftth_port_count) as ftth_port_rate
+from sqmdb_cost.kuandai_ftth 
+where areal_type_name='小计' and sdate='2022-04-02'
+group by local_net_name
+order by local_net_name
+
+---网格,使用kuandai_ftth(率值:ftth_port_sts_count/ftth_port_count)
+select local_net_name,area_name,
+sum(ftth_port_count)/10000 as ftth_port_count,
+sum(ftth_port_sts_count)/10000 as ftth_port_sts_count,
+sum(ftth_port_sts_count)/sum(ftth_port_count) as ftth_port_rate
+from sqmdb_cost.kuandai_ftth
+where areal_type_name!='小计' and sdate='2022-04-02'
+group by local_net_name,area_name
+order by local_net_name,area_name
+
+select date_trunc('month',current_date - interval '1' month)
+union
+select date_trunc('month',current_date)
+
+

+ 14 - 0
Scripts/29_30.sql

@@ -0,0 +1,14 @@
+--29、单公里承载用户数
+--30、单载频载扇用户数
+---地市
+select 
+month_id,
+city_name,
+total_user_yw,
+total_user_kd,
+total_gl,
+zps_total_with5g,
+round((total_user_yw+total_user_kd)/total_gl) as per_km_user,
+round(total_user_yw/zps_total_with5g) as per_zps_user
+from sqmdb_cost.jt_number_city jnc 
+where month_id='202203'

+ 41 - 0
Scripts/IDC报表.sql

@@ -0,0 +1,41 @@
+select * from
+(select smonth,sname,idc_in_total,idc_in_jtft,idc_in_qzc,(idc_in_total-idc_in_jtft-idc_in_qzc) as chazhi 
+from sqmdb_cost.chengben_shengnei where smonth='202203' and stype='地市') byue
+join 
+(select smonth,sname,idc_in_total,idc_in_jtft,idc_in_qzc,(idc_in_total-idc_in_jtft-idc_in_qzc) as chazhi 
+from sqmdb_cost.chengben_shengnei where smonth='202202' and stype='地市') syue
+on byue.sname=syue.sname
+
+--create table sqmdb_cost.rpt_tmp as 
+select smonth,sname,'IDC业务收入' as vtype,idc_in_total as amount from sqmdb_cost.chengben_shengnei where smonth='202203' and stype='地市'
+union all 
+select smonth,sname,'集团分摊收入' as vtype,idc_in_jtft as amount from sqmdb_cost.chengben_shengnei where smonth='202203' and stype='地市'
+union all 
+select smonth,sname,'轻资产运营收入' as vtype,idc_in_qzc as amount from sqmdb_cost.chengben_shengnei where smonth='202203' and stype='地市'
+union all
+select smonth,sname,'减去分摊及轻资产收入' as vtype,(idc_in_total-idc_in_jtft-idc_in_qzc) as amount from sqmdb_cost.chengben_shengnei where smonth='202203' and stype='地市'
+
+
+select sname,
+sum(column4+column5)*0.1512/10000 as id_19,
+sum(column4+column5)*0.8488/10000 as id_20,
+sum(column19)/10000 as id_21,
+sum(column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115)/10000 as id_23,
+sum(column108)/10000 as id_24,
+sum(column5)/10000 as id_25_p2
+from sqmdb_cost.report50 r 
+where period_type='M' and smonth between '202201' and '202207' and stype='分省展现' and sname ='河北' group by sname
+union all
+select sname,
+(column4+column5)*0.1512/10000 as id_19,
+(column4+column5)*0.8488/10000 as id_20,
+(column19)/10000 as id_21,
+(column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115)/10000 as id_23,
+(column108)/10000 as id_24,
+(column5)/10000 as id_25_p2
+from sqmdb_cost.report50 r 
+where period_type='Y' and smonth='202207' and stype='分省展现' and sname ='河北'
+
+
+--网运成本专业分解表-归集+横向分摊+调差_年_分省展现_01合并
+select * from sqmdb_cost.report50 where sname='河北' and period_type='Y' and smonth='202207'

+ 31 - 0
Scripts/SDR汇聚表检查.sql

@@ -0,0 +1,31 @@
+--查看入库表大小
+select sdate,rat,sum(l4_dl_throughput +l4_ul_throughput)/1024/1024/1024/1024 as flow_tb 
+from sqmdb_bak.sdrflow_daily 
+where rat in ('6','9') group by sdate,rat;
+
+--手动创建分区
+--select sqmdb_bak.sdrflow_partition_daily();
+--CREATE TABLE sqmdb_bak.sdrflow_daily_20220801 PARTITION OF sqmdb_bak.sdrflow_daily FOR VALUES FROM ('2022-08-01 00:00:00') TO ('2022-08-02 00:00:00');
+--CREATE INDEX "sqmdb_bak.sdrflow_daily_20220801_sdate" ON sqmdb_bak.sdrflow_daily_20220801 USING btree(sdate);
+
+--查看分区表大小
+select relname,pg_size_pretty(pg_relation_size(relid)) 
+from pg_stat_user_tables 
+where schemaname='sqmdb_bak' and relname like '%sdrflow_daily%' order by relname desc;
+
+
+select sdate,count(*),sum(l4_dw_throughput+l4_ul_throughput)/1024/1024/1024/1024 as flow_tb
+from o2p.sdr_0_4g_flow_cell_day group by sdate order by sdate desc
+
+
+select sdate,count(*),sum(l4_dw_throughput+l4_ul_throughput)/1024/1024/1024/1024 as flow_tb
+from o2p.sdr_0_4g_flow_enb_day group by sdate order by sdate desc
+
+
+select sdate,count(*),sum(l4_dw_throughput+l4_ul_throughput)/1024/1024/1024/1024 as flow_tb
+from o2p.sdr_2_5g_flow_cell_day group by sdate order by sdate desc
+
+
+select sdate,count(*),sum(dl_throughput_m+ul_throughput_m)/1024/1024/1024/1024 as flow_tb
+from o2p.sdr_1_5g_flow_base_day group by sdate order by sdate desc
+

+ 17 - 0
Scripts/bigscreen/chengben_center_city.sql

@@ -0,0 +1,17 @@
+--中间屏 分地市预算进度
+--chengben_center_city_202203.csv
+select 
+cs.smonth,
+dg.city_sname as city_name,
+cs.cost_total as total_cost,
+ys.total_ys,
+cs.cost_total/ys.total_ys as rate_ys,
+dg.city_code*100 as city_code
+from
+(select smonth,sname,cost_total from sqmdb_cost.chengben_shengnei where stype='地市' and smonth='202204') cs
+join
+(select city_name||'_河北' as city_name,total_ys from sqmdb_cost.yusuan_shengnei) ys 
+on cs.sname=ys.city_name
+join 
+(select distinct city_code,city_pro,city_sname from sqmdb_cost.dict_grid) dg
+on cs.sname=dg.city_pro

+ 42 - 0
Scripts/bigscreen/chengben_exception_1_grid.sql

@@ -0,0 +1,42 @@
+--租赁费(chengben_exception_1_grid_202203.csv)
+----横向匹配 局站表a <- 合同索引b <- 合同系统c <- 铁塔全量表d
+select tb1.*,tb2.city_code*100 as city_code,tb3.area_code from
+(select 
+distinct
+t1.sdate,
+t1.city_name,
+t1.area_name,
+t1.station_sid,
+t1.station_sname,
+t1.property_type,
+t1.sid as hetong_sid,
+t1.hetong_yuezujin as cost_hetong,
+t1.tower_code,
+t1.tower_cost as cost_tower,
+t1.cost_total,
+t2.cbzx,
+t2.cbzx_cost_avg,
+t1.cost_total/t2.cbzx_cost_avg as cost_rate
+from (
+select 
+a.station_sid,a.station_sname,a.city_name,a.area_name,a.property_type,a.station_level,a.tower_code,
+c.yuezujin as hetong_yuezujin,--合同系统月租金(由合同总月份数和总金额计算得出)
+c.cname,c.cfname,c.cbzx as hetong_cbzx,c.sid,c.sname,
+d.sdate,e.cbzx as tower_cbzx,d.site_addr_id,d.total_cost as tower_cost,
+(coalesce(c.yuezujin,0)+coalesce(d.total_cost,0)) as cost_total,--总费用(合同月租金使用合同系统值)
+case when c.cbzx is null then e.cbzx else c.cbzx end as cbzx
+from sqmdb_cost.station3 a
+left join sqmdb_cost.station_hetong b on a.station_sid=b.station_sid
+left join sqmdb_cost.hetong_new c on c.sid=b.hetong_sid
+left join (select sdate,site_addr_id,sum(total_cost) as total_cost from sqmdb_cost.tower3 where sdate='202204' group by sdate,site_addr_id) d on a.tower_code=d.site_addr_id
+left join sqmdb_cost.dict_tower_cbzx e on a.tower_code=e.tower_code) t1
+left join (select * from sqmdb_cost.v_tower_cost_cbzx where sdate='202204') t2 
+on t1.sdate=t2.sdate::varchar and t1.cbzx=t2.cbzx
+where t1.cost_total/t2.cbzx_cost_avg>1.5) tb1
+left join 
+(select distinct city_code,city_name from sqmdb_cost.dict_grid) tb2
+on tb1.city_name=tb2.city_name
+left join 
+(select distinct city_code,city_name,area_code,area_name from sqmdb_cost.dict_grid) tb3
+on tb1.city_name=tb3.city_name and tb1.area_name=tb3.area_name
+order by tb2.city_code,tb3.area_code

+ 28 - 0
Scripts/bigscreen/chengben_exception_2_grid.sql

@@ -0,0 +1,28 @@
+--电费单价(新)使用局站级的电费预提明细
+--(chengben_exception_2_grid_202203.csv)
+select 
+yn.smonth,
+yn.city_name,
+yn.area_name,
+s.station_sid,
+s.station_sname,
+yn.meter_type_name,
+yn.accrued_cost,
+yn.accrued_power,
+case when accrued_power=0 then 0 else yn.accrued_cost/yn.accrued_power end as eprice,
+yn.cost_unit_name,
+dg1.city_code*100 as city_code,
+dg2.area_code
+from sqmdb_cost.ytmx_new yn
+left join sqmdb_cost.station_nenghao sn on yn.build_code_short=sn.nh_sid_short
+left join sqmdb_cost.station3 s on sn.station_sid=s.station_sid
+left join (select distinct city_code,city_name from sqmdb_cost.dict_grid) dg1
+on yn.city_name=dg1.city_name
+left join 
+(select distinct city_code,city_name,area_code,area_name from sqmdb_cost.dict_grid) dg2
+on yn.city_name=dg2.city_name and yn.area_name=dg2.area_name
+where yn.meter_type_name in ('12-01 | 转供手抄表','21-01 | 定额协议表','21-02 | 铁塔包干表')
+and s.station_sid is not null
+and (case when accrued_power=0 then 0 else yn.accrued_cost/yn.accrued_power end)>0.8
+and yn.smonth='202204'
+order by dg1.city_code,dg2.area_code

+ 19 - 0
Scripts/bigscreen/chengben_exception_3_grid.sql

@@ -0,0 +1,19 @@
+--局站能耗
+--(chengben_exception_3_grid_202203.csv)
+select 
+distinct
+t1.smonth,
+dg.city_code*100 as city_code,
+dg.area_code,
+t2.station_sid,
+t2.station_name,
+t1.nh_total,
+t2.accrued_power,
+t2.cost_unit_name
+from sqmdb_cost.v_station_omc_nh t1--专业网管能耗
+join
+(select yn.smonth,yn.city_name,yn.area_name,sn.station_sid,station_name,yn.accrued_cost,yn.accrued_power,yn.cost_unit_name from sqmdb_cost.ytmx_new yn
+join sqmdb_cost.station_nenghao sn on yn.build_code_short=sn.nh_sid_short) t2 --能耗表能耗
+on t1.smonth=t2.smonth and t1.station_sid=t2.station_sid
+left join sqmdb_cost.dict_grid dg on t2.city_name=dg.city_name and t2.area_name=dg.area_name
+where t1.smonth='202204'

+ 25 - 0
Scripts/bigscreen/chengben_other_1_city_b10.sql

@@ -0,0 +1,25 @@
+--02、网运成本占收比(省内口径)
+--chengben_other_1_city_b10_202203.csv
+select t1.*,
+case 
+when sname='北京' then 110000
+when sname='天津' then 120000
+when sname='河北' then 130000
+when sname='山西' then 140000
+when sname='内蒙古' then 150000
+when sname='辽宁' then 210000
+when sname='吉林' then 220000
+when sname='黑龙江' then 230000
+when sname='山东' then 370000
+when sname='河南' then 410000
+else t2.city_code*100 end as city_code 
+from
+(select smonth,stype,sname,cost_total,income,
+cost_total/income as cost_income_rate
+from sqmdb_cost.chengben_shengnei
+--where stype='北10'
+--where stype='地市'
+where smonth='202204') t1
+left join
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid) t2
+on t1.sname=t2.city_pro

+ 15 - 0
Scripts/bigscreen/chengben_other_2_b10.sql

@@ -0,0 +1,15 @@
+--14、单载频载扇能耗(月)
+---北10
+---chengben_other_2_b10_202203.csv
+select 
+smonth,
+sname,
+cost_yw,
+cost_hexin,
+cost_total,
+zps_num_no5g,
+cost_zps_no5g,
+prov_code
+from sqmdb_cost.rpt_dzpzs_cost_b10 
+where smonth='202204'
+order by prov_code

+ 17 - 0
Scripts/bigscreen/chengben_other_2_city.sql

@@ -0,0 +1,17 @@
+--14、单载频载扇能耗(月)
+---地市
+---chengben_other_2_city_202203.csv
+select 
+smonth,
+city_sname,
+cost_yw,
+cost_hexin,
+cost_total,
+zps_num_with5g,
+zps_num_no5g,
+cost_zps_with5g,
+cost_zps_no5g,
+city_code
+from sqmdb_cost.rpt_dzpzs_cost_city
+where smonth='202204'
+order by city_code

+ 24 - 0
Scripts/bigscreen/chengben_other_2_grid.sql

@@ -0,0 +1,24 @@
+---µ¥ÔØƵÔØÉÈÄܺÄ-Íø¸ñ
+---chengben_other_2_grid_202203.csv
+select 
+grid.smonth,
+grid.city_name,
+grid.grid_name,
+grid.cost_yw,
+grid.cost_hexin,
+grid.cost_total,
+grid.zps_num_with5g,
+null zps_num_no5g,
+grid.cost_zps_with5g,
+null cost_zps_no5g,
+dg1.city_code*100 as city_code,
+dg2.area_code
+from sqmdb_cost.rpt_dzpzs_cost_grid grid
+left join
+(select distinct city_code,grid_city_name from sqmdb_cost.dict_grid) dg1
+on grid.city_name=dg1.grid_city_name
+left join
+(select distinct city_code,area_code,grid_city_name,grid_name from sqmdb_cost.dict_grid) dg2
+on grid.city_name=dg2.grid_city_name and grid.grid_name=dg2.grid_name
+where smonth='202204'
+order by dg1.city_code,dg2.area_code

+ 23 - 0
Scripts/bigscreen/chengben_other_3_b10.sql

@@ -0,0 +1,23 @@
+--13、单端口能耗成本(月)
+---北10
+---chengben_other_3_b10_202203.csv
+select 
+smonth,
+sname,
+cost_nenghao,
+port_inuse as ftth_port_count,
+cost_port_nenghao,
+case 
+when sname='北京' then 110000
+when sname='天津' then 120000
+when sname='河北' then 130000
+when sname='山西' then 140000
+when sname='内蒙古' then 150000
+when sname='辽宁' then 210000
+when sname='吉林' then 220000
+when sname='黑龙江' then 230000
+when sname='山东' then 370000
+when sname='河南' then 410000
+end as prov_code 
+from sqmdb_cost.rpt_dport_cost_b10
+where smonth='202204'

+ 16 - 0
Scripts/bigscreen/chengben_other_3_city.sql

@@ -0,0 +1,16 @@
+--13、单端口能耗成本(月)
+---地市
+---chengben_other_3_city_202203.csv
+select
+c.smonth,
+dg.city_name,
+c.cost_nenghao,
+c.port_inuse as ftth_port_count,
+c.cost_port_nenghao,
+dg.city_code*100 as city_code
+from sqmdb_cost.rpt_dport_cost_city c
+join
+(select distinct city_code,city_sname,city_name from sqmdb_cost.dict_grid) dg
+on c.city_sname=dg.city_sname
+where smonth='202204'
+order by dg.city_code

+ 14 - 0
Scripts/bigscreen/chengben_other_3_grid.sql

@@ -0,0 +1,14 @@
+---Íř¸ń
+---chengben_other_3_grid_202203.csv
+select 
+smonth,
+city_sname as city_name,
+grid_name as area_name,
+cost_nenghao,
+ftth_port_count,
+cost_port_nenghao,
+city_code*100 as city_code,
+area_code
+from sqmdb_cost.rpt_dport_cost_grid
+where smonth='202204'
+order by city_code,area_code

+ 31 - 0
Scripts/bigscreen/chengben_other_4_b10.sql

@@ -0,0 +1,31 @@
+--16、单站铁塔租赁费(月)
+---北10数据(select * from sqmdb_cost.report50016)
+---chengben_other_4_b10_202203.csv
+select smonth,sname,column1 as tower_cost_avg_b10,
+case 
+when sname='北京' then 110000
+when sname='天津' then 120000
+when sname='河北' then 130000
+when sname='山西' then 140000
+when sname='内蒙古' then 150000
+when sname='辽宁' then 210000
+when sname='吉林' then 220000
+when sname='黑龙江' then 230000
+when sname='山东' then 370000
+when sname='河南' then 410000
+end as prov_code 
+from sqmdb_cost.report50016
+where sname in ('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202204'
+order by case
+when sname='北京' then 1
+when sname='天津' then 2
+when sname='河北' then 3
+when sname='山西' then 4
+when sname='内蒙古' then 5
+when sname='辽宁' then 6
+when sname='吉林' then 7
+when sname='黑龙江' then 8
+when sname='山东' then 9
+when sname='河南' then 10
+end

+ 15 - 0
Scripts/bigscreen/chengben_other_4_city.sql

@@ -0,0 +1,15 @@
+---ÌúËþµ¥Õ¾×âÁÞ·Ñ-µØÊÐ
+---chengben_other_4_city_202203.csv
+select 
+c.smonth,
+c.city_name,
+c.tower_cost as tower_cost_total,
+c.tower_num_avg as tower_num,
+c.tower_cost_avg as tower_cost_avg_city,
+dg.city_code*100 as city_code
+from sqmdb_cost.rpt_tower_cost_city c
+join
+(select distinct city_code,city_sname from sqmdb_cost.dict_grid) dg
+on c.city_name=dg.city_sname
+where smonth='202204'
+order by dg.city_code

+ 20 - 0
Scripts/bigscreen/chengben_other_4_grid.sql

@@ -0,0 +1,20 @@
+---Íø¸ñ
+---chengben_other_4_grid_202203.csv
+select 
+grid.smonth as sdate,
+grid.city_name as city_operator,
+grid.area_tower as area_operator,
+grid.tower_cost as tower_cost_total,
+grid.tower_num_avg as tower_num,
+grid.tower_cost_avg as tower_cost_avg_area,
+dg1.city_code*100 as city_code,
+dg2.area_code
+from sqmdb_cost.rpt_tower_cost_grid grid
+left join
+(select distinct city_code,city_sname from sqmdb_cost.dict_grid) dg1
+on grid.city_name=dg1.city_sname
+left join
+(select distinct city_sname,area_code,area_tower from sqmdb_cost.dict_grid) dg2
+on grid.city_name=dg2.city_sname and grid.area_tower=dg2.area_tower
+where smonth='202204'
+order by dg1.city_code,dg2.area_code

+ 21 - 0
Scripts/bigscreen/chengben_quzhun_1_a_grid.sql

@@ -0,0 +1,21 @@
+---1-a.转供电+定额包干累计成本占比(%)
+---chengben_quzhun_1_a_grid_202203.csv
+select 
+t1.*,
+t2.city_code*100 as city_code,
+t3.area_code
+from
+(select smonth,city_name,area_name,
+sum(accrued_cost) as total_cost,
+sum(case when y.meter_type_name in ('12-01 | 转供手抄表','21-01 | 定额协议表','21-02 | 铁塔包干表') then accrued_cost else 0 end) as zgd_cost,
+sum(case when y.meter_type_name in ('12-01 | 转供手抄表','21-01 | 定额协议表','21-02 | 铁塔包干表') then accrued_cost else 0 end)/sum(accrued_cost) as zgd_cost_rate
+from sqmdb_cost.ytmx_new y 
+group by smonth,city_name,area_name) t1
+left join
+(select distinct city_code,city_name from sqmdb_cost.dict_grid) t2
+on t1.city_name=t2.city_name
+join 
+(select distinct city_code,city_name,area_code,area_name from sqmdb_cost.dict_grid) t3
+on t1.city_name=t3.city_name and t1.area_name=t3.area_name
+where t1.smonth='202204'
+order by t2.city_code,t3.area_code

+ 21 - 0
Scripts/bigscreen/chengben_quzhun_1_b_grid.sql

@@ -0,0 +1,21 @@
+---1-b.铁塔独享站成本占比
+---chengben_quzhun_1_b_grid_202203.csv
+----网格
+select 
+t1.*,
+t2.city_code*100 as city_code,
+t3.area_code 
+from
+(select sdate,city_operator,area_operator,
+sum(total_cost) as cost_total,
+sum(case when is_duxiang='独享' then total_cost else 0 end) as cost_du,
+sum(case when is_duxiang='独享' then total_cost else 0 end)/sum(total_cost) as cost_du_rate
+from sqmdb_cost.tower2 where sdate='202204'
+group by sdate,city_operator,area_operator) t1
+left join
+(select distinct city_code,city_name from sqmdb_cost.dict_grid) t2
+on t1.city_operator=t2.city_name
+left join 
+(select distinct city_code,city_name,area_code,area_tower from sqmdb_cost.dict_grid) t3
+on t1.city_operator=t3.city_name and t1.area_operator=t3.area_tower
+order by t2.city_code,t3.area_code

+ 34 - 0
Scripts/bigscreen/chengben_quzhun_1_c_grid.sql

@@ -0,0 +1,34 @@
+---1-c.大于2倍铁塔单站租赁费三方站点占比
+---chengben_quzhun_1_c_grid_202203.csv
+----网格
+select 
+t1.*,
+t2.city_code*100 as city_code,
+t3.area_code 
+from
+(select sdate,city_name,area_name,
+sum(case when property_type='租用第三方' then 1 else 0 end) as cost_over2b_3rd_num,
+count(*) as station_num,
+sum(case when property_type='租用第三方' then 1 else 0 end)/count(*)::numeric as over_rate_3rd
+from(
+select *,
+cost_site.cost_tower/cost_cbzx.cbzx_cost_avg as cost_rate
+from
+(select station_sid,city_name,area_name,property_type,tower_code from sqmdb_cost.station3 s where s.property_type in ('租用铁塔','租用第三方')) st
+join
+(select sdate,site_addr_id,sum(total_cost) as cost_tower from sqmdb_cost.tower3 t group by sdate,site_addr_id) cost_site
+on st.tower_code=cost_site.site_addr_id
+join sqmdb_cost.dict_tower_cbzx dtc on st.tower_code=dtc.tower_code
+join 
+(select sdate as cbzx_sdate,cbzx,cbzx_cost_avg from sqmdb_cost.v_tower_cost_cbzx) cost_cbzx
+on cost_site.sdate=cost_cbzx.cbzx_sdate::varchar and dtc.cbzx=cost_cbzx.cbzx
+where cost_site.cost_tower/cost_cbzx.cbzx_cost_avg>2
+and cost_site.sdate='202204') a
+group by sdate,city_name,area_name) t1
+left join
+(select distinct city_code,city_name from sqmdb_cost.dict_grid) t2
+on t1.city_name=t2.city_name
+left join 
+(select distinct city_code,city_name,area_code,area_name from sqmdb_cost.dict_grid) t3
+on t1.city_name=t3.city_name and t1.area_name=t3.area_name
+order by t2.city_code,t3.area_code

+ 16 - 0
Scripts/bigscreen/chengben_quzhun_1_d_city.sql

@@ -0,0 +1,16 @@
+--14、单载频载扇能耗(月)
+---地市
+---chengben_other_2_city_202203.csv
+select 
+smonth,
+city_sname,
+cost_yw,
+cost_hexin,
+cost_total,
+zps_num_with5g,
+zps_num_no5g,
+cost_zps_with5g,
+cost_zps_no5g,
+city_code
+from sqmdb_cost.rpt_dzpzs_cost_city
+where smonth='202204'

+ 23 - 0
Scripts/bigscreen/chengben_quzhun_1_d_grid.sql

@@ -0,0 +1,23 @@
+---µ¥ÔØƵÔØÉÈÄܺÄ-Íø¸ñ
+---chengben_other_2_grid_202203.csv
+select 
+grid.smonth,
+grid.city_name,
+grid.grid_name,
+grid.cost_yw,
+grid.cost_hexin,
+grid.cost_total,
+grid.zps_num_with5g,
+null zps_num_no5g,
+grid.cost_zps_with5g,
+null cost_zps_no5g,
+dg1.city_code*100 as city_code,
+dg2.area_code
+from sqmdb_cost.rpt_dzpzs_cost_grid grid
+left join
+(select distinct city_code,grid_city_name from sqmdb_cost.dict_grid) dg1
+on grid.city_name=dg1.grid_city_name
+left join
+(select distinct city_code,area_code,grid_city_name,grid_name from sqmdb_cost.dict_grid) dg2
+on grid.city_name=dg2.grid_city_name and grid.grid_name=dg2.grid_name
+where smonth='202204'

+ 34 - 0
Scripts/bigscreen/chengben_quzhun_1_e_grid.sql

@@ -0,0 +1,34 @@
+---1-e.基站单站租金合理性(局站维度)与【看异常】租赁费匹配顺序相同
+---chengben_quzhun_1_e_grid_202203.csv
+----网格
+----判断标准:大于2倍铁塔成本中心平均租费
+select tb1.*,tb2.city_code*100 as city_code,tb3.area_code from
+(select sdate,city_name,area_name,
+count(*) as station_num,
+sum(case when cost_rate>2 then 1 else 0 end) as over2_num,
+sum(case when cost_rate>2 then 1 else 0 end)/count(*)::numeric as over2_rate
+from
+(select distinct t1.sdate,t1.city_name,t1.area_name,t1.station_sid,t1.cost_total as cost_station,
+t2.cbzx_cost_avg,t1.cost_total/t2.cbzx_cost_avg as cost_rate from 
+(select 
+a.station_sid,a.station_sname,a.city_name,a.area_name,a.property_type,a.station_level,a.tower_code,
+c.yuezujin as hetong_yuezujin,--合同系统月租金(由合同总月份数和总金额计算得出)
+c.cname,c.cfname,c.cbzx as hetong_cbzx,c.sid,c.sname,
+d.sdate,e.cbzx as tower_cbzx,d.service_tracking_id,d.site_addr_id,d.stype,d.is_duxiang,d.total_cost as tower_cost,
+(coalesce(c.yuezujin,0)+coalesce(d.total_cost,0)) as cost_total,--总费用(合同月租金使用合同系统值)
+case when c.cbzx is null then e.cbzx else c.cbzx end as cbzx
+from sqmdb_cost.station3 a
+left join sqmdb_cost.station_hetong b on a.station_sid=b.station_sid
+left join sqmdb_cost.hetong_new c on c.sid=b.hetong_sid
+left join sqmdb_cost.tower3 d on a.tower_code=d.site_addr_id
+left join sqmdb_cost.dict_tower_cbzx e on a.tower_code=e.tower_code) t1
+left join sqmdb_cost.v_tower_cost_cbzx t2 on t1.sdate=t2.sdate::varchar and t1.cbzx=t2.cbzx
+where t1.sdate='202204') tmp
+group by sdate,city_name,area_name) tb1
+left join 
+(select distinct city_code,city_name from sqmdb_cost.dict_grid) tb2
+on tb1.city_name=tb2.city_name
+left join 
+(select distinct city_code,city_name,area_code,area_name from sqmdb_cost.dict_grid) tb3
+on tb1.city_name=tb3.city_name and tb1.area_name=tb3.area_name
+order by tb2.city_code,tb3.area_code

+ 21 - 0
Scripts/bigscreen/chengben_quzhun_2_city.sql

@@ -0,0 +1,21 @@
+---2.有合同无局站
+---chengben_quzhun_2_city_202203.csv
+with vt as (select a.sid,a.sname,a.cname,a.cfname,a.cbzx,a.yuezujin,
+b.city_name,b.city_code,b.district_code,b.hetong_sid,b.station_sid as station_sid_i,
+c.station_sid as station_sid_s,
+(case 
+when b.hetong_sid is not null and c.station_sid is not null then '有合同有局站'--'合同系统有,资源系统没'
+when b.hetong_sid is null or (b.hetong_sid is not null and c.station_sid is null) then '有合同无局站'--'合同系统有,资源系统没有' 
+else '其他'
+end) as check_result
+from sqmdb_cost.hetong_new a
+left join sqmdb_cost.station_hetong b on a.sid=b.hetong_sid
+left join sqmdb_cost.station3 c on b.station_sid=c.station_sid)
+select '202204' as sdate,t1.*,t2.city_code*100 as city_code from
+(select substr(cname,5,length(cname)-7) as city,sid,sname,yuezujin as cost_hetong,cbzx
+from vt where check_result='有合同无局站') t1
+left join 
+(select distinct city_code,city_sname from sqmdb_cost.dict_grid) t2 
+on t1.city=t2.city_sname
+where t2.city_code is not null
+order by t2.city_code,t1.cost_hetong desc

+ 19 - 0
Scripts/bigscreen/chengben_quzhun_3_city.sql

@@ -0,0 +1,19 @@
+---3.有能耗无局站
+---chengben_quzhun_3_city_202203.csv
+with vt as (select nh.smonth,nh.city_name,nh.build_code,nh.build_name,nh.accrued_cost,nh.cost_unit_name,s.station_sid,
+(case when s.station_sid is not null then '有能耗有局站' else '有能耗无局站' end) as check_result
+from
+(select smonth,city_name,area_name,build_code_short,build_code,build_name,cost_unit_name,accrued_cost from sqmdb_cost.ytmx_new) nh
+left join
+(select distinct station_sid,nh_sid_short from sqmdb_cost.station_nenghao) sy
+on nh.build_code_short=sy.nh_sid_short
+left join
+(select station_sid,station_sname from sqmdb_cost.station3) s
+on sy.station_sid=s.station_sid
+where nh.smonth='202204')
+select t1.*,t2.city_code*100 as city_code from 
+(select smonth,city_name,build_code,build_name,accrued_cost,cost_unit_name from vt where check_result='有能耗无局站') t1
+left join
+(select distinct city_code,city_name from sqmdb_cost.dict_grid) t2 
+on t1.city_name=t2.city_name
+order by t2.city_code,t1.cost_unit_name

+ 18 - 0
Scripts/bigscreen/chengben_quzhun_4_city.sql

@@ -0,0 +1,18 @@
+---4.有铁塔订单无局站
+---chengben_quzhun_4_city_202203.csv
+with vt as (select t.sdate,t.city_operator,t.site_addr_id,dtc.tower_name,t.total_cost,dtc.cbzx,tf.fzd_id,
+(case when tf.fzd_id is not null then '有铁塔订单有局站' else '有铁塔订单无局站' end) as check_result
+from
+(select sdate,city_operator,site_addr_id,sum(total_cost) as total_cost from sqmdb_cost.tower3 
+group by sdate,city_operator,site_addr_id) t
+left join sqmdb_cost.dict_tower_cbzx dtc 
+on t.site_addr_id=dtc.tower_code 
+left join sqmdb_cost.tower_fzd tf 
+on t.city_operator=tf.city_name and t.site_addr_id||E'\t'=tf.tower_code
+where t.sdate='202204')
+select t1.*,t2.city_code*100 as city_code from 
+(select sdate,city_operator,site_addr_id,tower_name,total_cost,cbzx from vt where check_result='有铁塔订单无局站') t1
+left join
+(select distinct city_code,city_name from sqmdb_cost.dict_grid) t2 
+on t1.city_operator=t2.city_name
+order by t2.city_code,t1.tower_name,t1.total_cost desc

+ 35 - 0
Scripts/bigscreen/chengben_self_1_b10.sql

@@ -0,0 +1,35 @@
+--预算进度
+--chengben_self_1_b10_202203.csv
+--03、网运成本预算完成进度(集团口径)
+---北10
+select smonth,sname,
+column1 as total_cost,
+column2 as total_ys,
+case when column2=0 then 1 else column1/column2 end as rate_ys,
+case 
+when sname='北京' then 110000
+when sname='天津' then 120000
+when sname='河北' then 130000
+when sname='山西' then 140000
+when sname='内蒙古' then 150000
+when sname='辽宁' then 210000
+when sname='吉林' then 220000
+when sname='黑龙江' then 230000
+when sname='山东' then 370000
+when sname='河南' then 410000
+end as prov_code
+from sqmdb_cost.report50002 
+where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202204'
+order by case
+when sname='北京' then 1
+when sname='天津' then 2
+when sname='河北' then 3
+when sname='山西' then 4
+when sname='内蒙古' then 5
+when sname='辽宁' then 6
+when sname='吉林' then 7
+when sname='黑龙江' then 8
+when sname='山东' then 9
+when sname='河南' then 10
+end

+ 37 - 0
Scripts/bigscreen/chengben_self_2_city.sql

@@ -0,0 +1,37 @@
+--主要成本(万元)
+--chengben_self_2_city_202203.csv
+---地市
+select 
+jt.*,
+sn.cost_total_sn,
+sn.cost_fix_sn,
+t2.city_code*100 as city_code 
+from
+(select 
+a.smonth,
+a.sname,
+a.cost_total_jt,
+a.cost_rental_tower_jt,
+a.cost_nenghao_jt,
+a.cost_rental_3rd_jt
+from
+(select '202204' as smonth,sname,stype,
+sum(column1)/10000 as cost_total_jt,
+sum(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115)/10000 as cost_nenghao_jt,
+sum(column12+column15+column16)/10000 as cost_rental_3rd_jt,
+sum(column2+column3)/10000 as cost_rental_tower_jt
+from sqmdb_cost.report50 where period_type='M' and stype ='北方省汇总展现'
+and smonth between '202201' and '202204' group by sname,stype) a
+left join
+(select report_id,smonth,sname,stype,column4 as income_year from sqmdb_cost.report80040) b
+on a.smonth=b.smonth and a.sname=b.sname
+where 
+a.sname in ('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')) jt
+left join
+(select smonth,sname,cost_total as cost_total_sn,cost_fix as cost_fix_sn from sqmdb_cost.chengben_shengnei where stype='地市') sn
+on jt.smonth=sn.smonth and jt.sname=sn.sname 
+left join
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid) t2
+on jt.sname=t2.city_pro
+where jt.smonth='202204'
+order by t2.city_code

+ 239 - 0
Scripts/bigscreen_new/T_NET_COST_MAG_MON.sql

@@ -0,0 +1,239 @@
+--北10
+select 
+ys.smonth as "MONTH_ID",--账期
+dz.area_id as "AREA_ID",--区域
+dz.area_name as "AREA_NAME",--区域名称
+dz.p_id as "P_ID",--父ID
+round(ys.rate_ys*100,2) as "BUDGET_RATE_ZM",--预算进度
+round(cb.cost_total_sn,2) as "COST_TOT_ZM", --主体成本-总额-万元-账面,
+round(cb.cost_rental_tower_jt,2) as "COST_TT_ZM",--铁塔租赁费-总额-万元-账面
+round(cb.cost_nenghao_jt,2) as "COST_NET_ZM",--网络能耗-总额-万元-账面
+round(cb.cost_rental_3rd_jt,2) as "COST_3RD_ZM",--第三方租赁费-总额-万元-账面
+round(cb.cost_fix_sn,2) as "COST_XL_FEE_ZM",--修理及运行维护费-总额-万元-账面
+null as "BUDGET_RATE_TC",--预算进度-剔除后
+null as "COST_TOT_TC",--主体成本-总额-万元-剔除后
+null as "COST_TT_TC",--铁塔租赁费-总额-万元-剔除后
+null as "COST_NET_TC",--网络能耗-总额-万元-剔除后
+null as "COST_3RD_TC",--第三方租赁费-总额-万元-剔除后
+null as "COST_XL_FEE_TC",--修理及运行维护费-总额-万元-剔除后
+round(cb_zsb.cost_income_rate*100,2) as "COST_RATE_ZM",--成本占收比-账面
+null as "COST_RATE_TC",--成本占收比-剔除后
+round(zpzs.cost_zps_no5g,2) as "CELL_COST",--单载频/载扇能耗-万元
+round(ports.cost_port_nenghao,2) as "PORT_COST",--单端口能耗-万元
+round(tower.tower_cost_avg,2) as "SITE_COST"--铁塔单站租赁费-万元
+from
+(select smonth,sname,
+column1 as total_cost,
+column2 as total_ys,
+case when column2=0 then 1 else column1/column2 end as rate_ys
+from sqmdb_cost.report50002 
+where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202205') ys
+join
+--主要成本
+(select
+jt.smonth,
+jt.sname,
+sn.cost_total_sn,
+jt.cost_total_jt,
+jt.cost_rental_tower_jt,
+jt.cost_nenghao_jt,
+jt.cost_rental_3rd_jt,
+sn.cost_fix_sn
+from
+(select 
+a.smonth,
+a.sname,
+a.cost_total_jt,
+a.cost_rental_tower_jt,
+a.cost_nenghao_jt,
+a.cost_rental_3rd_jt
+from
+(select smonth,sname,stype,
+(column1)/10000 as cost_total_jt,
+(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115)/10000 as cost_nenghao_jt,
+(column12+column15+column16)/10000 as cost_rental_3rd_jt,
+(column2+column3)/10000 as cost_rental_tower_jt
+from sqmdb_cost.report50 where period_type='M' and stype ='分省展现'
+and smonth='202205') a
+where a.sname in ('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')) jt
+left join
+(select smonth,sname,cost_total as cost_total_sn,cost_fix as cost_fix_sn from sqmdb_cost.chengben_shengnei_m where stype='北10' and smonth='202205') sn
+on jt.smonth=sn.smonth and jt.sname=sn.sname) cb
+on ys.smonth=cb.smonth and ys.sname=cb.sname
+join
+--成本占收比
+(select
+smonth,
+sname,
+cost_total,
+income,
+cost_total/income as cost_income_rate
+from sqmdb_cost.chengben_shengnei
+where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南') 
+and smonth='202205') cb_zsb
+on ys.smonth=cb_zsb.smonth and ys.sname=cb_zsb.sname
+join
+(select smonth,sname,cost_zps_no5g from sqmdb_cost.rpt_dzpzs_cost_b10 where smonth='202205') zpzs
+on ys.smonth=zpzs.smonth and ys.sname=zpzs.sname
+join
+(select smonth,sname,cost_port_nenghao from sqmdb_cost.rpt_dport_cost_b10 where smonth='202205') ports
+on ys.smonth=ports.smonth and ys.sname=ports.sname
+join 
+(select smonth,sname,column1 as tower_cost_avg from sqmdb_cost.report50016
+where sname in ('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202205') tower
+on ys.smonth=tower.smonth and ys.sname=tower.sname
+join sqmdb_cost.dict_zzjg dz on ys.sname=dz.area_name 
+
+union all
+
+--地市
+select 
+ys.smonth as "MONTH_ID",--账期
+dz.area_id as "AREA_ID",--区域
+dz.area_name as "AREA_NAME",--区域名称
+dz.p_id as "P_ID",--父ID
+round(ys.rate_ys*100,2) as "BUDGET_RATE_ZM",--预算进度
+round(cb.cost_total_sn,2) as "COST_TOT_ZM", --主体成本-总额-万元-账面,
+round(cb.cost_rental_tower_jt,2) as "COST_TT_ZM",--铁塔租赁费-总额-万元-账面
+round(cb.cost_nenghao_jt,2) as "COST_NET_ZM",--网络能耗-总额-万元-账面
+round(cb.cost_rental_3rd_jt,2) as "COST_3RD_ZM",--第三方租赁费-总额-万元-账面
+round(cb.cost_fix_sn,2) as "COST_XL_FEE_ZM",--修理及运行维护费-总额-万元-账面
+null as "BUDGET_RATE_TC",--预算进度-剔除后
+null as "COST_TOT_TC",--主体成本-总额-万元-剔除后
+null as "COST_TT_TC",--铁塔租赁费-总额-万元-剔除后
+null as "COST_NET_TC",--网络能耗-总额-万元-剔除后
+null as "COST_3RD_TC",--第三方租赁费-总额-万元-剔除后
+null as "COST_XL_FEE_TC",--修理及运行维护费-总额-万元-剔除后
+round(cb_zsb.cost_income_rate*100,2) as "COST_RATE_ZM",--成本占收比-账面
+null as "COST_RATE_TC",--成本占收比-剔除后
+round(zpzs.cost_zps_with5g,2) as "CELL_COST",--单载频/载扇能耗-万元
+round(ports.cost_port_nenghao,2) as "PORT_COST",--单端口能耗-万元
+round(tower.tower_cost_avg,2) as "SITE_COST"--铁塔单站租赁费-万元
+from
+(select 
+cs.smonth,
+dg.city_sname as sname,
+'地市' as stype,
+cs.cost_total as total_cost,
+ys.total_ys,
+cs.cost_total/ys.total_ys as rate_ys
+from
+(select smonth,sname,cost_total from sqmdb_cost.chengben_shengnei where stype='地市' and smonth='202205') cs
+join
+(select city_name||'_河北' as city_name,total_ys from sqmdb_cost.yusuan_shengnei) ys 
+on cs.sname=ys.city_name
+join 
+(select distinct city_code,city_pro,city_sname from sqmdb_cost.dict_grid) dg
+on cs.sname=dg.city_pro) ys
+join
+--主要成本
+(select
+jt.smonth,
+t2.city_sname,
+sn.cost_total_sn,
+jt.cost_total_jt,
+jt.cost_rental_tower_jt,
+jt.cost_nenghao_jt,
+jt.cost_rental_3rd_jt,
+sn.cost_fix_sn
+from
+(select 
+a.smonth,
+a.sname,
+a.cost_total_jt,
+a.cost_rental_tower_jt,
+a.cost_nenghao_jt,
+a.cost_rental_3rd_jt
+from
+(select smonth,sname,stype,
+(column1)/10000 as cost_total_jt,
+(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115)/10000 as cost_nenghao_jt,
+(column12+column15+column16)/10000 as cost_rental_3rd_jt,
+(column2+column3)/10000 as cost_rental_tower_jt
+from sqmdb_cost.report50 where period_type='M' and stype ='北方省汇总展现'
+and smonth='202205') a
+where a.sname in ('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')) jt
+left join
+(select smonth,sname,cost_total as cost_total_sn,cost_fix as cost_fix_sn from sqmdb_cost.chengben_shengnei_m where stype='地市' and smonth='202205') sn
+on jt.smonth=sn.smonth and jt.sname=sn.sname 
+left join
+(select distinct city_code,city_pro,city_sname from sqmdb_cost.dict_grid) t2
+on jt.sname=t2.city_pro) cb
+on ys.smonth=cb.smonth and ys.sname=cb.city_sname
+join
+--成本占收比
+(select 
+smonth,
+city_name_short(sname) as sname,
+cost_total,
+income,
+cost_total/income as cost_income_rate
+from sqmdb_cost.chengben_shengnei
+where stype='地市' and smonth='202205') cb_zsb
+on ys.smonth=cb_zsb.smonth and ys.sname=cb_zsb.sname
+join
+(select smonth,city_sname,cost_zps_with5g from sqmdb_cost.rpt_dzpzs_cost_city where smonth='202205') zpzs
+on ys.smonth=zpzs.smonth and ys.sname=zpzs.city_sname
+join
+(select smonth,city_sname,cost_port_nenghao from sqmdb_cost.rpt_dport_cost_city where smonth='202205') ports
+on ys.smonth=ports.smonth and ys.sname=ports.city_sname
+join 
+(select smonth,city_name,tower_cost_avg from sqmdb_cost.rpt_tower_cost_city where smonth='202205') tower
+on ys.smonth=tower.smonth and ys.sname=tower.city_name
+join sqmdb_cost.dict_zzjg dz on ys.sname=dz.area_name 
+
+union all 
+
+--网格
+select 
+cb.smonth as "MONTH_ID",--账期
+dz.area_id as "AREA_ID",--区域
+coalesce(dz.area_name, dcg.grid_name) as area_name,--区域名称
+coalesce(dz.p_id, dcg.city_code*100) as p_id,--父ID
+null as "BUDGET_RATE_ZM",--预算进度
+round(cb.cost_total_jt,2) as "COST_TOT_ZM", --主体成本-总额-万元-账面,
+round(cb.cost_rental_tower_jt,2) as "COST_TT_ZM",--铁塔租赁费-总额-万元-账面
+round(cb.cost_nenghao_jt,2) as "COST_NET_ZM",--网络能耗-总额-万元-账面
+round(cb.cost_rental_3rd_jt,2) as "COST_3RD_ZM",--第三方租赁费-总额-万元-账面
+null as "COST_XL_FEE_ZM",--修理及运行维护费-总额-万元-账面
+null as "BUDGET_RATE_TC",--预算进度-剔除后
+null as "COST_TOT_TC",--主体成本-总额-万元-剔除后
+null as "COST_TT_TC",--铁塔租赁费-总额-万元-剔除后
+null as "COST_NET_TC",--网络能耗-总额-万元-剔除后
+null as "COST_3RD_TC",--第三方租赁费-总额-万元-剔除后
+null as "COST_XL_FEE_TC",--修理及运行维护费-总额-万元-剔除后
+null as "COST_RATE_ZM",--成本占收比-账面
+null as "COST_RATE_TC",--成本占收比-剔除后
+round(zpzs.cost_zps_with5g,2) as "CELL_COST",--单载频/载扇能耗-万元
+round(ports.cost_port_nenghao,2) as "PORT_COST",--单端口能耗-万元
+round(tower.tower_cost_avg,2) as "SITE_COST"--铁塔单站租赁费-万元
+from
+--主要成本
+(select 
+jt.*,
+dgc.grid_code 
+from
+(select 
+smonth,
+city_name_short(city_name) as city_name,
+grid_name,
+column1/10000 as cost_total_jt,
+(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115)/10000 as cost_nenghao_jt,
+(column12+column15+column16)/10000 as cost_rental_3rd_jt,
+(column2+column3)/10000 as cost_rental_tower_jt
+from sqmdb_cost.report49 where period_type='M' and smonth='202205') jt
+left join sqmdb_cost.dict_grid_code dgc on jt.city_name=dgc.city_name and trim(jt.grid_name)=trim(dgc.grid_name)
+where dgc.grid_code is not null) cb
+join
+(select smonth,grid_code,cost_zps_with5g from sqmdb_cost.rpt_dzpzs_cost_grid where smonth='202205') zpzs
+on cb.grid_code=zpzs.grid_code
+join
+(select smonth,grid_code,cost_port_nenghao from sqmdb_cost.rpt_dport_cost_grid where smonth='202205') ports
+on cb.grid_code=ports.grid_code
+join 
+(select smonth,grid_code,tower_cost_avg from sqmdb_cost.rpt_tower_cost_grid where smonth='202205') tower
+on cb.grid_code=tower.grid_code
+join sqmdb_cost.dict_code_grid dcg on cb.grid_code=dcg.grid_code
+left join sqmdb_cost.dict_zzjg dz on dcg.area_code=dz.area_id

+ 241 - 0
Scripts/bigscreen_new/T_NET_COST_MAG_MON_旧版累计成本.sql

@@ -0,0 +1,241 @@
+--北10
+select 
+ys.smonth as "MONTH_ID",--账期
+dz.area_id as "AREA_ID",--区域
+dz.area_name as "AREA_NAME",--区域名称
+dz.p_id as "P_ID",--父ID
+round(ys.rate_ys*100,2) as "BUDGET_RATE_ZM",--预算进度
+round(cb.cost_total_jt,2) as "COST_TOT_ZM", --主体成本-总额-万元-账面,
+round(cb.cost_rental_tower_jt,2) as "COST_TT_ZM",--铁塔租赁费-总额-万元-账面
+round(cb.cost_nenghao_jt,2) as "COST_NET_ZM",--网络能耗-总额-万元-账面
+round(cb.cost_rental_3rd_jt,2) as "COST_3RD_ZM",--第三方租赁费-总额-万元-账面
+round(cb.cost_fix_sn,2) as "COST_XL_FEE_ZM",--修理及运行维护费-总额-万元-账面
+null as "BUDGET_RATE_TC",--预算进度-剔除后
+null as "COST_TOT_TC",--主体成本-总额-万元-剔除后
+null as "COST_TT_TC",--铁塔租赁费-总额-万元-剔除后
+null as "COST_NET_TC",--网络能耗-总额-万元-剔除后
+null as "COST_3RD_TC",--第三方租赁费-总额-万元-剔除后
+null as "COST_XL_FEE_TC",--修理及运行维护费-总额-万元-剔除后
+round(cb_zsb.cost_income_rate*100,2) as "COST_RATE_ZM",--成本占收比-账面
+null as "COST_RATE_TC",--成本占收比-剔除后
+round(zpzs.cost_zps_no5g,2) as "CELL_COST",--单载频/载扇能耗-万元
+round(ports.cost_port_nenghao,2) as "PORT_COST",--单端口能耗-万元
+round(tower.tower_cost_avg,2) as "SITE_COST"--铁塔单站租赁费-万元
+from
+(select smonth,sname,
+column1 as total_cost,
+column2 as total_ys,
+case when column2=0 then 1 else column1/column2 end as rate_ys
+from sqmdb_cost.report50002 
+where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202205') ys
+join
+--主要成本
+(select
+jt.smonth,
+jt.sname,
+sn.cost_total_sn,
+jt.cost_total_jt,
+jt.cost_rental_tower_jt,
+jt.cost_nenghao_jt,
+jt.cost_rental_3rd_jt,
+sn.cost_fix_sn
+from
+(select 
+a.smonth,
+a.sname,
+a.cost_total_jt,
+a.cost_rental_tower_jt,
+a.cost_nenghao_jt,
+a.cost_rental_3rd_jt
+from
+(select '202205' as smonth,sname,stype,
+sum(column1)/10000 as cost_total_jt,
+sum(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115)/10000 as cost_nenghao_jt,
+sum(column12+column15+column16)/10000 as cost_rental_3rd_jt,
+sum(column2+column3)/10000 as cost_rental_tower_jt
+from sqmdb_cost.report50 where period_type='M' and stype ='分省展现'
+and smonth between '202201' and '202205' group by sname,stype) a
+where a.sname in ('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')) jt
+left join
+(select smonth,sname,cost_total as cost_total_sn,cost_fix as cost_fix_sn from sqmdb_cost.chengben_shengnei where stype='地市') sn
+on jt.smonth=sn.smonth and jt.sname=sn.sname 
+where jt.smonth='202205') cb
+on ys.smonth=cb.smonth and ys.sname=cb.sname
+join
+--成本占收比
+(select 
+smonth,
+sname,
+cost_total,
+income,
+cost_total/income as cost_income_rate
+from sqmdb_cost.chengben_shengnei
+where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南') 
+and smonth='202205') cb_zsb
+on ys.smonth=cb_zsb.smonth and ys.sname=cb_zsb.sname
+join
+(select smonth,sname,cost_zps_no5g from sqmdb_cost.rpt_dzpzs_cost_b10 where smonth='202205') zpzs
+on ys.smonth=zpzs.smonth and ys.sname=zpzs.sname
+join
+(select smonth,sname,cost_port_nenghao from sqmdb_cost.rpt_dport_cost_b10 where smonth='202205') ports
+on ys.smonth=ports.smonth and ys.sname=ports.sname
+join 
+(select smonth,sname,column1 as tower_cost_avg from sqmdb_cost.report50016
+where sname in ('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202205') tower
+on ys.smonth=tower.smonth and ys.sname=tower.sname
+join sqmdb_cost.dict_zzjg dz on ys.sname=dz.area_name 
+
+union all
+
+--地市
+select 
+ys.smonth as "MONTH_ID",--账期
+dz.area_id as "AREA_ID",--区域
+dz.area_name as "AREA_NAME",--区域名称
+dz.p_id as "P_ID",--父ID
+round(ys.rate_ys*100,2) as "BUDGET_RATE_ZM",--预算进度
+round(cb.cost_total_sn,2) as "COST_TOT_ZM", --主体成本-总额-万元-账面,
+round(cb.cost_rental_tower_jt,2) as "COST_TT_ZM",--铁塔租赁费-总额-万元-账面
+round(cb.cost_nenghao_jt,2) as "COST_NET_ZM",--网络能耗-总额-万元-账面
+round(cb.cost_rental_3rd_jt,2) as "COST_3RD_ZM",--第三方租赁费-总额-万元-账面
+round(cb.cost_fix_sn,2) as "COST_XL_FEE_ZM",--修理及运行维护费-总额-万元-账面
+null as "BUDGET_RATE_TC",--预算进度-剔除后
+null as "COST_TOT_TC",--主体成本-总额-万元-剔除后
+null as "COST_TT_TC",--铁塔租赁费-总额-万元-剔除后
+null as "COST_NET_TC",--网络能耗-总额-万元-剔除后
+null as "COST_3RD_TC",--第三方租赁费-总额-万元-剔除后
+null as "COST_XL_FEE_TC",--修理及运行维护费-总额-万元-剔除后
+round(cb_zsb.cost_income_rate*100,2) as "COST_RATE_ZM",--成本占收比-账面
+null as "COST_RATE_TC",--成本占收比-剔除后
+round(zpzs.cost_zps_with5g,2) as "CELL_COST",--单载频/载扇能耗-万元
+round(ports.cost_port_nenghao,2) as "PORT_COST",--单端口能耗-万元
+round(tower.tower_cost_avg,2) as "SITE_COST"--铁塔单站租赁费-万元
+from
+(select 
+cs.smonth,
+dg.city_sname as sname,
+'地市' as stype,
+cs.cost_total as total_cost,
+ys.total_ys,
+cs.cost_total/ys.total_ys as rate_ys
+from
+(select smonth,sname,cost_total from sqmdb_cost.chengben_shengnei where stype='地市' and smonth='202205') cs
+join
+(select city_name||'_河北' as city_name,total_ys from sqmdb_cost.yusuan_shengnei) ys 
+on cs.sname=ys.city_name
+join 
+(select distinct city_code,city_pro,city_sname from sqmdb_cost.dict_grid) dg
+on cs.sname=dg.city_pro) ys
+join
+--主要成本
+(select
+jt.smonth,
+t2.city_sname,
+sn.cost_total_sn,
+jt.cost_total_jt,
+jt.cost_rental_tower_jt,
+jt.cost_nenghao_jt,
+jt.cost_rental_3rd_jt,
+sn.cost_fix_sn
+from
+(select 
+a.smonth,
+a.sname,
+a.cost_total_jt,
+a.cost_rental_tower_jt,
+a.cost_nenghao_jt,
+a.cost_rental_3rd_jt
+from
+(select '202205' as smonth,sname,stype,
+sum(column1)/10000 as cost_total_jt,
+sum(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115)/10000 as cost_nenghao_jt,
+sum(column12+column15+column16)/10000 as cost_rental_3rd_jt,
+sum(column2+column3)/10000 as cost_rental_tower_jt
+from sqmdb_cost.report50 where period_type='M' and stype ='北方省汇总展现'
+and smonth between '202201' and '202205' group by sname,stype) a
+where a.sname in ('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')) jt
+left join
+(select smonth,sname,cost_total as cost_total_sn,cost_fix as cost_fix_sn from sqmdb_cost.chengben_shengnei where stype='地市') sn
+on jt.smonth=sn.smonth and jt.sname=sn.sname 
+left join
+(select distinct city_code,city_pro,city_sname from sqmdb_cost.dict_grid) t2
+on jt.sname=t2.city_pro
+where jt.smonth='202205') cb
+on ys.smonth=cb.smonth and ys.sname=cb.city_sname
+join
+--成本占收比
+(select 
+smonth,
+city_name_short(sname) as sname,
+cost_total,
+income,
+cost_total/income as cost_income_rate
+from sqmdb_cost.chengben_shengnei
+where stype='地市' and smonth='202205') cb_zsb
+on ys.smonth=cb_zsb.smonth and ys.sname=cb_zsb.sname
+join
+(select smonth,city_sname,cost_zps_with5g from sqmdb_cost.rpt_dzpzs_cost_city where smonth='202205') zpzs
+on ys.smonth=zpzs.smonth and ys.sname=zpzs.city_sname
+join
+(select smonth,city_sname,cost_port_nenghao from sqmdb_cost.rpt_dport_cost_city where smonth='202205') ports
+on ys.smonth=ports.smonth and ys.sname=ports.city_sname
+join 
+(select smonth,city_name,tower_cost_avg from sqmdb_cost.rpt_tower_cost_city where smonth='202205') tower
+on ys.smonth=tower.smonth and ys.sname=tower.city_name
+join sqmdb_cost.dict_zzjg dz on ys.sname=dz.area_name 
+
+union all 
+
+--网格
+select 
+cb.smonth as "MONTH_ID",--账期
+dz.area_id as "AREA_ID",--区域
+coalesce(dz.area_name, dcg.grid_name) as area_name,--区域名称
+coalesce(dz.p_id, dcg.city_code*100) as p_id,--父ID
+null as "BUDGET_RATE_ZM",--预算进度
+round(cb.cost_total_jt,2) as "COST_TOT_ZM", --主体成本-总额-万元-账面,
+round(cb.cost_rental_tower_jt,2) as "COST_TT_ZM",--铁塔租赁费-总额-万元-账面
+round(cb.cost_nenghao_jt,2) as "COST_NET_ZM",--网络能耗-总额-万元-账面
+round(cb.cost_rental_3rd_jt,2) as "COST_3RD_ZM",--第三方租赁费-总额-万元-账面
+null as "COST_XL_FEE_ZM",--修理及运行维护费-总额-万元-账面
+null as "BUDGET_RATE_TC",--预算进度-剔除后
+null as "COST_TOT_TC",--主体成本-总额-万元-剔除后
+null as "COST_TT_TC",--铁塔租赁费-总额-万元-剔除后
+null as "COST_NET_TC",--网络能耗-总额-万元-剔除后
+null as "COST_3RD_TC",--第三方租赁费-总额-万元-剔除后
+null as "COST_XL_FEE_TC",--修理及运行维护费-总额-万元-剔除后
+null as "COST_RATE_ZM",--成本占收比-账面
+null as "COST_RATE_TC",--成本占收比-剔除后
+round(zpzs.cost_zps_with5g,2) as "CELL_COST",--单载频/载扇能耗-万元
+round(ports.cost_port_nenghao,2) as "PORT_COST",--单端口能耗-万元
+round(tower.tower_cost_avg,2) as "SITE_COST"--铁塔单站租赁费-万元
+from
+--主要成本
+(select 
+jt.*,
+dgc.grid_code 
+from
+(select 
+smonth,
+city_name_short(city_name) as city_name,
+grid_name,
+column1/10000 as cost_total_jt,
+(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115)/10000 as cost_nenghao_jt,
+(column12+column15+column16)/10000 as cost_rental_3rd_jt,
+(column2+column3)/10000 as cost_rental_tower_jt
+from sqmdb_cost.report49 where period_type='Y' and smonth='202205') jt
+left join sqmdb_cost.dict_grid_code dgc on jt.city_name=dgc.city_name and trim(jt.grid_name)=trim(dgc.grid_name)
+where dgc.grid_code is not null) cb
+join
+(select smonth,grid_code,cost_zps_with5g from sqmdb_cost.rpt_dzpzs_cost_grid where smonth='202205') zpzs
+on cb.grid_code=zpzs.grid_code
+join
+(select smonth,grid_code,cost_port_nenghao from sqmdb_cost.rpt_dport_cost_grid where smonth='202205') ports
+on cb.grid_code=ports.grid_code
+join 
+(select smonth,grid_code,tower_cost_avg from sqmdb_cost.rpt_tower_cost_grid where smonth='202205') tower
+on cb.grid_code=tower.grid_code
+join sqmdb_cost.dict_code_grid dcg on cb.grid_code=dcg.grid_code
+left join sqmdb_cost.dict_zzjg dz on dcg.area_code=dz.area_id

+ 512 - 0
Scripts/bigscreen_new/T_NET_COST_MAG_TAB_ERROR_MON.sql

@@ -0,0 +1,512 @@
+with err_tw as(
+select 
+t1.smonth as month_id,--账期
+dz.area_id as area_id,--区域
+coalesce(dz.area_name, dcg.grid_name) as area_name,--区域名称
+coalesce(dz.p_id, dcg.city_code*100) as p_id,--父ID
+'1' as idx_id,--指标ID
+'铁塔租赁费异常指标' as idx_name,--指标名称
+t1.level_type as idx_level,--指标分级
+t1.total_num as idx_val_tot,--指标值-总
+t1.level_num::numeric as idx_val_err,--指标值-异常
+dcg.city_name as p_name--地市名称,用于汇聚地市指标
+from
+(select 
+smonth,grid_code,total_num,
+regexp_split_to_table(concat_ws('~','<1.5倍','1.5-2倍','2倍以上'),'~') level_type,
+regexp_split_to_table(concat_ws('~',level_1_num,level_2_num,level_3_num),'~') level_num
+from
+(select 
+smonth,grid_code,
+count(*) as total_num,
+sum(case when over_tower_cost_grid<1.5 then 1 else 0 end) as level_1_num,
+sum(case when over_tower_cost_grid>=1.5 and over_tower_cost_grid<=2 then 1 else 0 end) as level_2_num,
+sum(case when over_tower_cost_grid>2 then 1 else 0 end) as level_3_num
+from sqmdb_cost.rpt_baobiao_4_cgzf
+where tower_cost is not null 
+and tower_cost_grid is not null 
+and smonth='202205'
+group by smonth,grid_code) a) t1
+join sqmdb_cost.dict_code_grid dcg on t1.grid_code=dcg.grid_code 
+left join sqmdb_cost.dict_zzjg dz on dcg.area_code=dz.area_id),
+
+err_3rd as (
+select 
+t1.smonth as month_id,--账期
+dz.area_id as area_id,--区域
+coalesce(dz.area_name, dcg.grid_name) as area_name,--区域名称
+coalesce(dz.p_id, dcg.city_code*100) as p_id,--父ID
+'2' as idx_id,--指标ID
+'三方租赁费异常指标' as idx_name,--指标名称
+t1.level_type as idx_level,--指标分级
+t1.total_num as idx_val_tot,--指标值-总
+t1.level_num::numeric as idx_val_err,--指标值-异常
+dcg.city_name as p_name--地市名称,用于汇聚地市指标
+from
+(select 
+smonth,grid_code,total_num,
+regexp_split_to_table(concat_ws('~','<1.5倍','1.5-2倍','2倍以上'),'~') level_type,
+regexp_split_to_table(concat_ws('~',level_1_num,level_2_num,level_3_num),'~') level_num
+from
+(select 
+smonth,grid_code,
+count(*) as total_num,
+sum(case when ht_cost_grid_scene_bs<1.5 then 1 else 0 end) as level_1_num,
+sum(case when ht_cost_grid_scene_bs>=1.5 and ht_cost_grid_scene_bs<=2 then 1 else 0 end) as level_2_num,
+sum(case when ht_cost_grid_scene_bs>2 then 1 else 0 end) as level_3_num
+from sqmdb_cost.rpt_baobiao_4_cgzf
+where hetong_sid is not null and smonth='202205'
+group by smonth,grid_code) a) t1
+join sqmdb_cost.dict_code_grid dcg on t1.grid_code=dcg.grid_code 
+left join sqmdb_cost.dict_zzjg dz on dcg.area_code=dz.area_id),
+
+err_zgd as (
+select 
+t1.smonth as month_id ,--账期
+dz.area_id as area_id,--区域
+coalesce(dz.area_name, dcg.grid_name) as area_name,--区域名称
+coalesce(dz.p_id, dcg.city_code*100) as p_id,--父ID
+'3' as idx_id,--指标ID
+'转供电异常指标' as idx_name,--指标名称
+t1.level_type as idx_level,--指标分级
+t1.total_num as idx_val_tot,--指标值-总
+t1.level_num::numeric as idx_val_err,--指标值-异常
+dcg.city_name as p_name--地市名称,用于汇聚地市指标
+from
+(select 
+smonth,grid_code,total_num,
+regexp_split_to_table(concat_ws('~','8毛以下','8毛-1块','1块以上'),'~') level_type,
+regexp_split_to_table(concat_ws('~',level_1_num,level_2_num,level_3_num),'~') level_num
+from
+(select 
+smonth,grid_code,
+count(*) as total_num,
+sum(case when eprice<0.8 then 1 else 0 end) as level_1_num,
+sum(case when eprice>=0.8 and eprice<=1 then 1 else 0 end) as level_2_num,
+sum(case when eprice>1 then 1 else 0 end) as level_3_num
+from sqmdb_cost.rpt_baobiao_5_cgdf 
+where smonth='202205'
+group by smonth,grid_code) a) t1
+join sqmdb_cost.dict_code_grid dcg on t1.grid_code=dcg.grid_code 
+left join sqmdb_cost.dict_zzjg dz on dcg.area_code=dz.area_id),
+
+err_nh as (
+select 
+t1.smonth as month_id ,--账期
+dz.area_id as area_id,--区域
+coalesce(dz.area_name, dcg.grid_name) as area_name,--区域名称
+coalesce(dz.p_id, dcg.city_code*100) as p_id,--父ID
+'4' as idx_id,--指标ID
+'能耗异常指标' as idx_name,--指标名称
+t1.level_type as idx_level,--指标分级
+t1.total_num as idx_val_tot,--指标值-总
+t1.level_num::numeric as idx_val_err,--指标值-异常
+dcg.city_name as p_name--地市名称,用于汇聚地市指标
+from
+(select 
+smonth,grid_code,total_num,
+regexp_split_to_table(concat_ws('~','<1.5倍','1.5-2倍','2倍以上'),'~') level_type,
+regexp_split_to_table(concat_ws('~',level_1_num,level_2_num,level_3_num),'~') level_num
+from
+(select 
+smonth,grid_code,
+count(*) as total_num,
+sum(case when over_lilun_power<1.5 then 1 else 0 end) as level_1_num,
+sum(case when over_lilun_power>=1.5 and over_lilun_power<=2 then 1 else 0 end) as level_2_num,
+sum(case when over_lilun_power>2 then 1 else 0 end) as level_3_num
+from sqmdb_cost.rpt_baobiao_6_cgnh
+where smonth='202205'
+group by smonth,grid_code) a) t1
+join sqmdb_cost.dict_code_grid dcg on t1.grid_code=dcg.grid_code 
+left join sqmdb_cost.dict_zzjg dz on dcg.area_code=dz.area_id),
+
+--有合同无局站
+check_ht as (
+select 
+t1.smonth as month_id ,--账期
+dz.area_id as area_id,--区域
+coalesce(dz.area_name, dcg.grid_name) as area_name,--区域名称
+coalesce(dz.p_id, dcg.city_code*100) as p_id,--父ID
+'5' as idx_id,--指标ID
+'有合同无局站' as idx_name,--指标名称
+t1.level_type as idx_level,--指标分级
+t1.total_num as idx_val_tot,--指标值-总
+t1.level_num::numeric as idx_val_err,--指标值-异常
+dcg.city_name as p_name--地市名称,用于汇聚地市指标
+from
+(select 
+smonth,grid_code,total_num,
+regexp_split_to_table(concat_ws('~','有合同有局站','有合同无局站'),'~') level_type,
+regexp_split_to_table(concat_ws('~',has_num,no_num),'~') level_num
+from
+(select 
+smonth,grid_code,
+count(*) as total_num,
+sum(case when stype='有合同有局站' then 1 else 0 end) as has_num,
+sum(case when stype!='有合同有局站' then 1 else 0 end) as no_num
+from sqmdb_cost.err_has_ht_no_station
+group by smonth,grid_code) a) t1
+join sqmdb_cost.dict_code_grid dcg on t1.grid_code=dcg.grid_code 
+left join sqmdb_cost.dict_zzjg dz on dcg.area_code=dz.area_id),
+
+--有能耗无局站
+check_nh as (
+select 
+t1.smonth as month_id ,--账期
+dz.area_id as area_id,--区域
+coalesce(dz.area_name, dcg.grid_name) as area_name,--区域名称
+coalesce(dz.p_id, dcg.city_code*100) as p_id,--父ID
+'6' as idx_id,--指标ID
+'有能耗无局站' as idx_name,--指标名称
+t1.level_type as idx_level,--指标分级
+t1.total_num as idx_val_tot,--指标值-总
+t1.level_num::numeric as idx_val_err,--指标值-异常
+dcg.city_name as p_name--地市名称,用于汇聚地市指标
+from
+(select 
+smonth,grid_code,total_num,
+regexp_split_to_table(concat_ws('~','有能耗有局站','有能耗无局站'),'~') level_type,
+regexp_split_to_table(concat_ws('~',has_num,no_num),'~') level_num
+from
+(select 
+smonth,grid_code,
+count(*) as total_num,
+sum(case when stype='校验正常' then 1 else 0 end) as has_num,
+sum(case when stype!='校验正常' then 1 else 0 end) as no_num
+from sqmdb_cost.err_has_nh_no_station
+group by smonth,grid_code) a) t1
+join sqmdb_cost.dict_code_grid dcg on t1.grid_code=dcg.grid_code 
+left join sqmdb_cost.dict_zzjg dz on dcg.area_code=dz.area_id),
+
+--有铁塔订单无局站
+check_tw as (
+select 
+t1.smonth as month_id,--账期
+dz.area_id as area_id,--区域
+coalesce(dz.area_name, dcg.grid_name) as area_name,--区域名称
+coalesce(dz.p_id, dcg.city_code*100) as p_id,--父ID
+'7' as idx_id,--指标ID
+'有铁塔订单无局站' as idx_name,--指标名称
+t1.level_type as idx_level,--指标分级
+t1.total_num as idx_val_tot,--指标值-总
+t1.level_num::numeric as idx_val_err,--指标值-异常
+dcg.city_name as p_name--地市名称,用于汇聚地市指标
+from (select 
+smonth,grid_code,total_num,
+regexp_split_to_table(concat_ws('~','有铁塔订单有局站','有铁塔订单无局站'),'~') level_type,
+regexp_split_to_table(concat_ws('~',has_num,no_num),'~') level_num
+from
+(select 
+smonth,grid_code,
+count(*) as total_num,
+sum(case when stype='有铁塔订单有局站' then 1 else 0 end) as has_num,
+sum(case when stype!='有铁塔订单有局站' then 1 else 0 end) as no_num
+from sqmdb_cost.err_has_tw_no_station
+group by smonth,grid_code) a) t1
+join sqmdb_cost.dict_code_grid dcg on t1.grid_code=dcg.grid_code 
+left join sqmdb_cost.dict_zzjg dz on dcg.area_code=dz.area_id),
+
+--无成本中心数据
+missing_cbzx as (select 
+t1.smonth as month_id ,--账期
+dz.area_id as area_id,--区域
+coalesce(dz.area_name, dcg.grid_name) as area_name,--区域名称
+coalesce(dz.p_id, dcg.city_code*100) as p_id,--父ID
+'8' as idx_id,--指标ID
+'无成本中心数据' as idx_name,--指标名称
+t1.level_type as idx_level,--指标分级
+t1.total_num as idx_val_tot,--指标值-总
+t1.level_num::numeric as idx_val_err,--指标值-异常
+dcg.city_name as p_name--地市名称,用于汇聚地市指标
+from
+(select 
+smonth,grid_code,total_num,
+regexp_split_to_table(concat_ws('~','有成本中心','无成本中心'),'~') level_type,
+regexp_split_to_table(concat_ws('~',has_num,no_num),'~') level_num
+from
+(select smonth,grid_code,
+sum(total_num) as total_num,
+sum(has_num) as has_num,
+sum(no_num) as no_num 
+from
+(select 
+smonth,grid_code,
+count(*) as total_num,
+sum(case when cbzx is not null then 1 else 0 end) as has_num,
+sum(case when cbzx is null then 1 else 0 end) as no_num
+from sqmdb_cost.err_has_ht_no_station
+group by smonth,grid_code
+union all 
+select 
+smonth,grid_code,
+count(*) as total_num,
+sum(case when cost_unit_name is not null then 1 else 0 end) as has_num,
+sum(case when cost_unit_name is null then 1 else 0 end) as no_num
+from sqmdb_cost.err_has_nh_no_station 
+group by smonth,grid_code
+union all 
+select 
+smonth,grid_code,
+count(*) as total_num,
+sum(case when cbzx is not null then 1 else 0 end) as has_num,
+sum(case when cbzx is null then 1 else 0 end) as no_num
+from sqmdb_cost.err_has_tw_no_station 
+group by smonth,grid_code) u
+group by smonth,grid_code) a) t1
+join sqmdb_cost.dict_code_grid dcg on t1.grid_code=dcg.grid_code 
+left join sqmdb_cost.dict_zzjg dz on dcg.area_code=dz.area_id)
+
+--铁塔租赁费异常指标-网格
+select 
+month_id as "MONTH_ID",
+area_id as "AREA_ID",
+area_name as "AREA_NAME",
+p_id as "P_ID",
+idx_id as "IDX_ID",
+idx_name as "IDX_NAME",
+idx_level as "IDX_LEVEL",
+idx_val_tot as "IDX_VAL_TOT",
+idx_val_err as "IDX_VAL_ERR"
+from err_tw
+
+union all
+
+--铁塔租赁费异常指标-地市
+select 
+c.month_id as "MONTH_ID",
+c.p_id as "AREA_ID",
+c.p_name as "AREA_NAME",
+z.p_id as "P_ID",
+c.idx_id as "IDX_ID",
+c.idx_name as "IDX_NAME",
+c.idx_level as "IDX_LEVEL",
+sum(c.idx_val_tot) as "IDX_VAL_TOT",
+sum(c.idx_val_err) as "IDX_VAL_ERR"
+from err_tw c
+left join sqmdb_cost.dict_zzjg z on c.p_id=z.area_id 
+group by c.month_id,c.p_id,z.p_id,c.p_name,c.idx_id,c.idx_name,c.idx_level
+
+union all
+
+--三方租赁费异常指标-网格
+select 
+month_id as "MONTH_ID",
+area_id as "AREA_ID",
+area_name as "AREA_NAME",
+p_id as "P_ID",
+idx_id as "IDX_ID",
+idx_name as "IDX_NAME",
+idx_level as "IDX_LEVEL",
+idx_val_tot as "IDX_VAL_TOT",
+idx_val_err as "IDX_VAL_ERR"
+from err_3rd
+
+union all
+
+--三方租赁费异常指标-地市
+select 
+c.month_id as "MONTH_ID",
+c.p_id as "AREA_ID",
+c.p_name as "AREA_NAME",
+z.p_id as "P_ID",
+c.idx_id as "IDX_ID",
+c.idx_name as "IDX_NAME",
+c.idx_level as "IDX_LEVEL",
+sum(c.idx_val_tot) as "IDX_VAL_TOT",
+sum(c.idx_val_err) as "IDX_VAL_ERR"
+from err_3rd c
+left join sqmdb_cost.dict_zzjg z on c.p_id=z.area_id 
+group by c.month_id,c.p_id,z.p_id,c.p_name,c.idx_id,c.idx_name,c.idx_level
+
+union all 
+
+--转供电异常指标-网格
+select 
+month_id as "MONTH_ID",
+area_id as "AREA_ID",
+area_name as "AREA_NAME",
+p_id as "P_ID",
+idx_id as "IDX_ID",
+idx_name as "IDX_NAME",
+idx_level as "IDX_LEVEL",
+idx_val_tot as "IDX_VAL_TOT",
+idx_val_err as "IDX_VAL_ERR"
+from err_zgd
+
+union all
+
+--转供电异常指标-地市
+select 
+c.month_id as "MONTH_ID",
+c.p_id as "AREA_ID",
+c.p_name as "AREA_NAME",
+z.p_id as "P_ID",
+c.idx_id as "IDX_ID",
+c.idx_name as "IDX_NAME",
+c.idx_level as "IDX_LEVEL",
+sum(c.idx_val_tot) as "IDX_VAL_TOT",
+sum(c.idx_val_err) as "IDX_VAL_ERR"
+from err_zgd c
+left join sqmdb_cost.dict_zzjg z on c.p_id=z.area_id 
+group by c.month_id,c.p_id,z.p_id,c.p_name,c.idx_id,c.idx_name,c.idx_level
+
+union all
+
+--能耗异常指标-网格
+select 
+month_id as "MONTH_ID",
+area_id as "AREA_ID",
+area_name as "AREA_NAME",
+p_id as "P_ID",
+idx_id as "IDX_ID",
+idx_name as "IDX_NAME",
+idx_level as "IDX_LEVEL",
+idx_val_tot as "IDX_VAL_TOT",
+idx_val_err as "IDX_VAL_ERR"
+from err_nh
+
+union all
+
+--能耗异常指标-地市
+select 
+c.month_id as "MONTH_ID",
+c.p_id as "AREA_ID",
+c.p_name as "AREA_NAME",
+z.p_id as "P_ID",
+c.idx_id as "IDX_ID",
+c.idx_name as "IDX_NAME",
+c.idx_level as "IDX_LEVEL",
+sum(c.idx_val_tot) as "IDX_VAL_TOT",
+sum(c.idx_val_err) as "IDX_VAL_ERR"
+from err_nh c
+left join sqmdb_cost.dict_zzjg z on c.p_id=z.area_id 
+group by c.month_id,c.p_id,z.p_id,c.p_name,c.idx_id,c.idx_name,c.idx_level
+
+union all 
+
+--有合同无局站-网格
+select 
+month_id as "MONTH_ID",
+area_id as "AREA_ID",
+area_name as "AREA_NAME",
+p_id as "P_ID",
+idx_id as "IDX_ID",
+idx_name as "IDX_NAME",
+idx_level as "IDX_LEVEL",
+idx_val_tot as "IDX_VAL_TOT",
+idx_val_err as "IDX_VAL_ERR"
+from check_ht
+
+union all
+
+--有合同无局站-地市
+select 
+c.month_id as "MONTH_ID",
+c.p_id as "AREA_ID",
+c.p_name as "AREA_NAME",
+z.p_id as "P_ID",
+c.idx_id as "IDX_ID",
+c.idx_name as "IDX_NAME",
+c.idx_level as "IDX_LEVEL",
+sum(c.idx_val_tot) as "IDX_VAL_TOT",
+sum(c.idx_val_err) as "IDX_VAL_ERR"
+from check_ht c
+left join sqmdb_cost.dict_zzjg z on c.p_id=z.area_id 
+group by c.month_id,c.p_id,z.p_id,c.p_name,c.idx_id,c.idx_name,c.idx_level
+
+union all 
+
+--有能耗无局站-网格
+select 
+month_id as "MONTH_ID",
+area_id as "AREA_ID",
+area_name as "AREA_NAME",
+p_id as "P_ID",
+idx_id as "IDX_ID",
+idx_name as "IDX_NAME",
+idx_level as "IDX_LEVEL",
+idx_val_tot as "IDX_VAL_TOT",
+idx_val_err as "IDX_VAL_ERR"
+from check_nh
+
+union all
+
+--有能耗无局站-地市
+select 
+c.month_id as "MONTH_ID",
+c.p_id as "AREA_ID",
+c.p_name as "AREA_NAME",
+z.p_id as "P_ID",
+c.idx_id as "IDX_ID",
+c.idx_name as "IDX_NAME",
+c.idx_level as "IDX_LEVEL",
+sum(c.idx_val_tot) as "IDX_VAL_TOT",
+sum(c.idx_val_err) as "IDX_VAL_ERR"
+from check_nh c
+left join sqmdb_cost.dict_zzjg z on c.p_id=z.area_id 
+group by c.month_id,c.p_id,z.p_id,c.p_name,c.idx_id,c.idx_name,c.idx_level
+
+union all 
+
+--有铁塔订单无局站-网格
+select 
+month_id as "MONTH_ID",
+area_id as "AREA_ID",
+area_name as "AREA_NAME",
+p_id as "P_ID",
+idx_id as "IDX_ID",
+idx_name as "IDX_NAME",
+idx_level as "IDX_LEVEL",
+idx_val_tot as "IDX_VAL_TOT",
+idx_val_err as "IDX_VAL_ERR"
+from check_tw
+
+union all
+
+--有铁塔订单无局站-地市
+select 
+c.month_id as "MONTH_ID",
+c.p_id as "AREA_ID",
+c.p_name as "AREA_NAME",
+z.p_id as "P_ID",
+c.idx_id as "IDX_ID",
+c.idx_name as "IDX_NAME",
+c.idx_level as "IDX_LEVEL",
+sum(c.idx_val_tot) as "IDX_VAL_TOT",
+sum(c.idx_val_err) as "IDX_VAL_ERR"
+from check_tw c
+left join sqmdb_cost.dict_zzjg z on c.p_id=z.area_id 
+group by c.month_id,c.p_id,z.p_id,c.p_name,c.idx_id,c.idx_name,c.idx_level
+
+union all 
+
+--无成本中心数据-网格
+select 
+month_id as "MONTH_ID",
+area_id as "AREA_ID",
+area_name as "AREA_NAME",
+p_id as "P_ID",
+idx_id as "IDX_ID",
+idx_name as "IDX_NAME",
+idx_level as "IDX_LEVEL",
+idx_val_tot as "IDX_VAL_TOT",
+idx_val_err as "IDX_VAL_ERR"
+from missing_cbzx
+
+union all
+
+--无成本中心数据-地市
+select 
+c.month_id as "MONTH_ID",
+c.p_id as "AREA_ID",
+c.p_name as "AREA_NAME",
+z.p_id as "P_ID",
+c.idx_id as "IDX_ID",
+c.idx_name as "IDX_NAME",
+c.idx_level as "IDX_LEVEL",
+sum(c.idx_val_tot) as "IDX_VAL_TOT",
+sum(c.idx_val_err) as "IDX_VAL_ERR"
+from missing_cbzx c
+left join sqmdb_cost.dict_zzjg z on c.p_id=z.area_id 
+group by c.month_id,c.p_id,z.p_id,c.p_name,c.idx_id,c.idx_name,c.idx_level
+

+ 114 - 0
Scripts/bigscreen_new/T_NET_COST_MAG_TAB_KPI_MON.sql

@@ -0,0 +1,114 @@
+--地市
+select
+zgd.smonth as "MONTH_ID",--账期
+dz.area_id as "AREA_ID",--区域
+dz.area_name as "AREA_NAME",--区域名称
+dz.p_id as "P_ID",--父ID
+round(zgd.zgd_cost_rate*100,2) as "ZGD_RATE",--转供电+定额包干累计成本占比(%)
+round(tower.cost_du_rate*100,2) as "TT_DX_RATE",--铁塔独享站成本占比(%)
+round(over2b.over_2b_3rd_rate*100,2) as "DY_2_RATE",--大于2倍铁塔单站租费三方站点占比(%)
+round(zpzs.cost_zps_with5g,2) as "CELL_COST_AVG",--单载频/载扇能耗(元/月)
+round(over2b.over_2b_rate*100,2) as "JZ_COST_AVG"--基站单站租金合理性(%)
+from
+---1-a.转供电+定额包干累计成本占比(%)
+(select 
+t1.*,
+dc.city_code
+from
+(select smonth,city_name,
+sum(accrued_cost) as total_cost,
+sum(case when y.meter_type_name in ('12-01 | 转供手抄表','21-01 | 定额协议表','21-02 | 铁塔包干表') then accrued_cost else 0 end) as zgd_cost,
+sum(case when y.meter_type_name in ('12-01 | 转供手抄表','21-01 | 定额协议表','21-02 | 铁塔包干表') then accrued_cost else 0 end)/sum(accrued_cost) as zgd_cost_rate
+from sqmdb_cost.ytmx_new y where smonth='202205'
+group by smonth,city_name) t1
+join sqmdb_cost.dict_city dc on t1.city_name=dc.city_name) zgd
+join 
+---1-b.铁塔独享站成本占比
+(select sdate,city_code,
+sum(total_cost) as cost_total,
+sum(case when is_duxiang='独享' then total_cost else 0 end) as cost_du,
+sum(case when is_duxiang='独享' then total_cost else 0 end)/sum(total_cost) as cost_du_rate
+from
+(select t.*,dc2.city_code from 
+(select distinct sdate,city_operator,site_addr_id,total_cost,is_duxiang 
+from sqmdb_cost.tower3 
+where stype in ('新建及共享改造','存量注入') and sdate='202205') t
+join sqmdb_cost.dict_city dc2 on t.city_operator=dc2.city_name) a
+group by sdate,city_code) tower
+on zgd.city_code=tower.city_code
+join
+---1-c.大于2倍铁塔单站租赁费三方站点占比
+---1-e.基站单站租金合理性(局站维度)
+(select 
+dc3.city_code,
+sum(case when tower_cost_avg=0 then 1 when zulin_type='租用第三方' and cost_total/tower_cost_avg>2 then 1 else 0 end) as over_2b_3rd_num,
+count(*) as over_2b_total_num,
+sum(case when tower_cost_avg=0 then 1 when zulin_type='租用第三方' and cost_total/tower_cost_avg>2 then 1 else 0 end)/count(*)::numeric as over_2b_3rd_rate,---1-c.大于2倍铁塔单站租赁费三方站点占比
+sum(case when tower_cost_avg=0 then 1 when cost_total/tower_cost_avg>2 then 1 else 0 end)/count(*)::numeric as over_2b_rate ---1-e.基站单站租金合理性(局站维度)规则:大于2倍铁塔单站租赁费站点占比
+from sqmdb_cost.err_station_has_tw_3rd es
+left join sqmdb_cost.dict_city dc3 on es.city_name=dc3.city_name
+group by dc3.city_code) over2b
+on zgd.city_code=over2b.city_code
+join
+(select smonth,city_code,cost_zps_with5g from sqmdb_cost.rpt_dzpzs_cost_city where smonth='202205') zpzs
+on zgd.city_code=zpzs.city_code
+join sqmdb_cost.dict_zzjg dz on zgd.city_code=dz.area_id 
+
+union all
+
+--网格
+select
+zgd.smonth as "MONTH_ID",--账期
+dz.area_id as "AREA_ID",--区域
+coalesce(dz.area_name, dcg.grid_name) as area_name,--区域名称
+coalesce(dz.p_id, dcg.city_code*100) as p_id,--父ID
+round(zgd.zgd_cost_rate*100,2) as "ZGD_RATE",--转供电+定额包干累计成本占比(%)
+round(tower.cost_du_rate*100,2) as "TT_DX_RATE",--铁塔独享站成本占比(%)
+round(over2b.over_2b_3rd_rate*100,2) as "DY_2_RATE",--大于2倍铁塔单站租费三方站点占比(%)
+round(zpzs.cost_zps_with5g,2) as "CELL_COST_AVG",--单载频/载扇能耗(元/月)
+round(over2b.over_2b_rate*100,2) as "JZ_COST_AVG"--基站单站租金合理性(%)
+from
+---1-a.转供电+定额包干累计成本占比(%)
+(select 
+t1.*,
+dgc.grid_code
+from
+(select smonth,city_name,area_name,
+sum(accrued_cost) as total_cost,
+sum(case when y.meter_type_name in ('12-01 | 转供手抄表','21-01 | 定额协议表','21-02 | 铁塔包干表') then accrued_cost else 0 end) as zgd_cost,
+sum(case when y.meter_type_name in ('12-01 | 转供手抄表','21-01 | 定额协议表','21-02 | 铁塔包干表') then accrued_cost else 0 end)/sum(accrued_cost) as zgd_cost_rate
+from sqmdb_cost.ytmx_new y where smonth='202205'
+group by smonth,city_name,area_name) t1
+left join sqmdb_cost.dict_grid_code dgc on city_name_short(t1.city_name)=dgc.city_name and trim(t1.area_name)=trim(dgc.grid_name)) zgd
+join 
+---1-b.铁塔独享站成本占比
+(select sdate,grid_code,
+sum(total_cost) as cost_total,
+sum(case when is_duxiang='独享' then total_cost else 0 end) as cost_du,
+sum(case when is_duxiang='独享' then total_cost else 0 end)/sum(total_cost) as cost_du_rate
+from
+(select t.*,dgc.grid_code from 
+(select distinct sdate,city_name_short(city_operator) as city_name,area_operator,site_addr_id,total_cost,is_duxiang 
+from sqmdb_cost.tower3 
+where stype in ('新建及共享改造','存量注入') and sdate='202205') t
+join sqmdb_cost.dict_grid_code dgc on t.city_name=dgc.city_name and trim(t.area_operator)=dgc.grid_name
+where dgc.grid_code is not null) a
+group by sdate,city_name,grid_code) tower
+on zgd.grid_code=tower.grid_code
+join
+---1-c.大于2倍铁塔单站租赁费三方站点占比
+---1-e.基站单站租金合理性(局站维度)
+(select 
+grid_code,
+sum(case when tower_cost_avg=0 then 1 when zulin_type='租用第三方' and cost_total/tower_cost_avg>2 then 1 else 0 end) as over_2b_3rd_num,
+count(*) as over_2b_total_num,
+sum(case when tower_cost_avg=0 then 1 when zulin_type='租用第三方' and cost_total/tower_cost_avg>2 then 1 else 0 end)/count(*)::numeric as over_2b_3rd_rate,---1-c.大于2倍铁塔单站租赁费三方站点占比
+sum(case when tower_cost_avg=0 then 1 when cost_total/tower_cost_avg>2 then 1 else 0 end)/count(*)::numeric as over_2b_rate ---1-e.基站单站租金合理性(局站维度)规则:大于2倍铁塔单站租赁费站点占比
+from sqmdb_cost.err_station_has_tw_3rd
+group by grid_code) over2b
+on zgd.grid_code=over2b.grid_code
+join
+(select smonth,grid_code,cost_zps_with5g from sqmdb_cost.rpt_dzpzs_cost_grid where smonth='202205') zpzs
+on zgd.grid_code=zpzs.grid_code
+join sqmdb_cost.dict_code_grid dcg on zgd.grid_code=dcg.grid_code
+left join sqmdb_cost.dict_zzjg dz on dcg.area_code=dz.area_id 

+ 18 - 0
Scripts/kpi31/01_b10.sql

@@ -0,0 +1,18 @@
+---北10
+select 
+smonth as MONTH_ID,
+'北10' as ZB_TYPE,
+sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'1' as ZB_CODE,
+'网运成本占收比(集团口径)' as ZB_NAME,
+'是' as IS_RATIO,
+column6 as QZ_FZ,
+column14 as QZ_FM,
+column6/column14 as BY_QZ
+from sqmdb_cost.report50003 
+where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202207'

+ 27 - 0
Scripts/kpi31/01_city.sql

@@ -0,0 +1,27 @@
+select 
+'202207' as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+c.city_code*100 as CITY_ID,
+a.sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'1' as ZB_CODE,
+'网运成本占收比(集团口径)' as ZB_NAME,
+'是' as IS_RATIO,
+a.cost_total as QZ_FZ,
+b.income_year as QZ_FM,--本年收入累计,
+case when b.income_year=0 then null else a.cost_total/b.income_year end as BY_QZ
+from
+(select sname,
+sum(column1)/10000 as cost_total--成本合计(包含人工)
+from sqmdb_cost.report50 where period_type='M' and smonth between '202201' and '202207' group by sname) a 
+left join
+(select report_id,smonth,sname,stype,column4 as income_year from sqmdb_cost.report80040 
+where period_type='M' and smonth='202207') b 
+on a.sname=b.sname
+left join
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid) c 
+on a.sname=c.city_pro
+where a.sname in ('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+order by c.city_code

+ 20 - 0
Scripts/kpi31/02_b10.sql

@@ -0,0 +1,20 @@
+--02、网运成本占收比(省内口径)
+select 
+cs.smonth as MONTH_ID,
+'北10' as ZB_TYPE,
+cs.sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'2' as ZB_CODE,
+'网运成本占收比(省内口径)' as ZB_NAME,
+'是' as IS_RATIO,
+cs.cost_total as QZ_FZ,
+r.column4 as QZ_FM,
+cs.cost_total/r.column4 as BY_QZ
+from sqmdb_cost.chengben_shengnei cs
+join sqmdb_cost.report80040 r on cs.smonth=r.smonth and cs.sname=r.sname
+where r.period_type='M' 
+and cs.stype='北10'
+and cs.smonth='202207'

+ 25 - 0
Scripts/kpi31/02_city.sql

@@ -0,0 +1,25 @@
+--02、网运成本占收比(省内口径)
+select 
+cs.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+cs.sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'2' as ZB_CODE,
+'网运成本占收比(省内口径)' as ZB_NAME,
+'是' as IS_RATIO,
+cs.cost_total as QZ_FZ,
+r.column4 as QZ_FM,
+cs.cost_total/r.column4 as BY_QZ
+from sqmdb_cost.chengben_shengnei cs
+join sqmdb_cost.report80040 r on cs.smonth=r.smonth and cs.sname=r.sname 
+ join 
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid) dg
+on cs.sname=dg.city_pro
+where r.period_type='M' 
+and cs.stype='地市'
+and cs.smonth='202207'
+order by dg.city_code
+

+ 19 - 0
Scripts/kpi31/03_b10.sql

@@ -0,0 +1,19 @@
+--03、网运成本预算完成进度(集团口径)
+---北10(顺序:北京 天津 河北 山西 内蒙古 辽宁 吉林 黑龙江 山东 河南)
+select 
+smonth as MONTH_ID,
+'北10' as ZB_TYPE,
+sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'3' as ZB_CODE,
+'网运成本预算完成进度(集团口径)' as ZB_NAME,
+'是' as IS_RATIO,
+column1 as QZ_FZ,
+column2 as QZ_FM,
+case when column2=0 then 1 else column1/column2 end as BY_QZ
+from sqmdb_cost.report50002 
+where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202207'

+ 25 - 0
Scripts/kpi31/04_city.sql

@@ -0,0 +1,25 @@
+--04、网运成本预算完成进度(省内口径)
+select 
+cs.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+dg.city_sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'4' as ZB_CODE,
+'网运成本预算完成进度(省内口径)' as ZB_NAME,
+'是' as IS_RATIO,
+cs.cost_total as QZ_FZ,
+ys.total_ys as QZ_FM,
+cs.cost_total/ys.total_ys as BY_QZ
+from
+(select smonth,sname,cost_total from sqmdb_cost.chengben_shengnei where stype='地市' and smonth='202207') cs
+join
+(select city_name||'_河北' as city_name,total_ys from sqmdb_cost.yusuan_shengnei) ys 
+on cs.sname=ys.city_name
+join 
+(select distinct city_code,city_pro,city_sname from sqmdb_cost.dict_grid) dg
+on cs.sname=dg.city_pro
+order by dg.city_code
+

+ 24 - 0
Scripts/kpi31/05_b10.sql

@@ -0,0 +1,24 @@
+--05、百元资产网运成本(集团口径)表九
+---北10
+select 
+'202206' as MONTH_ID,
+'北10' as ZB_TYPE,
+a.sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'5' as ZB_CODE,
+'百元资产网运成本(集团口径)' as ZB_NAME,
+'否' as IS_RATIO,
+a.cost_total as QZ_FZ,
+b.zichan as QZ_FM,
+a.cost_total/b.zichan*100 as BY_QZ
+from
+(select sname,sum(column1)/10000 as cost_total from sqmdb_cost.report50 
+where period_type='M' and stype='分省展现' and smonth between '202201' and '202206' group by sname) a
+left join
+(select sname,sum(column7+column8)/2 as zichan from sqmdb_cost.report80054 
+where period_type='M' and stype='分省展现' and smonth between '202201' and '202206' group by sname) b
+on a.sname=b.sname
+where a.sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')

+ 28 - 0
Scripts/kpi31/05_city.sql

@@ -0,0 +1,28 @@
+--05、百元资产网运成本(集团口径)表九
+---地市
+select 
+'202206' as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+a.sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'5' as ZB_CODE,
+'百元资产网运成本(集团口径)' as ZB_NAME,
+'否' as IS_RATIO,
+a.cost_total as QZ_FZ,
+b.zichan as QZ_FM,
+a.cost_total/b.zichan*100 as BY_QZ
+from
+(select sname,sum(column1)/10000 as cost_total from sqmdb_cost.report50 
+where period_type='M' and stype='北方省汇总展现' and smonth between '202201' and '202206' group by sname) a
+left join
+(select sname,sum(column7+column8)/2 as zichan from sqmdb_cost.report80054 
+where period_type='M' and smonth between '202201' and '202206' group by sname) b
+on a.sname=b.sname
+left join
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid) dg
+on a.sname=dg.city_pro
+where a.sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+order by dg.city_code

+ 24 - 0
Scripts/kpi31/06_b10.sql

@@ -0,0 +1,24 @@
+--06、百元资产网运成本(省内口径)
+---北10
+select 
+a.smonth as MONTH_ID,
+'北10' as ZB_TYPE,
+a.sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'6' as ZB_CODE,
+'百元资产网运成本(省内口径)' as ZB_NAME,
+'否' as IS_RATIO,
+a.cost_total as QZ_FZ,
+b.zichan as QZ_FM,
+a.cost_total/b.zichan*100 as BY_QZ
+from
+(select smonth,stype,sname,cost_total as cost_total from sqmdb_cost.chengben_shengnei 
+where stype='北10' and smonth='202206') a
+join
+(select sname,stype,sum(column7+column8)/2 as zichan from sqmdb_cost.report80054
+where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and stype='分省展现' and period_type='M' and smonth between '202201' and '202206' group by sname,stype) b
+on a.sname=b.sname

+ 28 - 0
Scripts/kpi31/06_city.sql

@@ -0,0 +1,28 @@
+--06、百元资产网运成本(省内口径)
+---地市
+select 
+a.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+a.sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'6' as ZB_CODE,
+'百元资产网运成本(省内口径)' as ZB_NAME,
+'否' as IS_RATIO,
+a.cost_total as QZ_FZ,
+b.zichan as QZ_FM,
+a.cost_total/b.zichan*100 as BY_QZ
+from
+(select smonth,stype,sname,cost_total from sqmdb_cost.chengben_shengnei 
+where stype='地市' and smonth='202206') a
+join
+(select sname,stype,sum(column7+column8)/2 as zichan from sqmdb_cost.report80054
+where sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and period_type='M' and smonth between '202201' and '202206' group by sname,stype) b
+on a.sname=b.sname
+join
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid) dg
+on a.sname=dg.city_pro
+order by dg.city_code

+ 28 - 0
Scripts/kpi31/07_b10.sql

@@ -0,0 +1,28 @@
+--07、百元净资产网运成本
+---北10
+select 
+'202206' as MONTH_ID,
+'北10' as ZB_TYPE,
+a.sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'7' as ZB_CODE,
+'百元净资产网运成本' as ZB_NAME,
+'否' as IS_RATIO,
+c.cost_total as QZ_FZ,
+a.zichan-b.zhejiu as QZ_FM,
+c.cost_total/(a.zichan-b.zhejiu)*100 as BY_QZ
+from 
+(select sname,stype,sum(column7+column8)/2 as zichan 
+from sqmdb_cost.report80054 where period_type='M' and smonth between '202201' and '202206' group by sname,stype) a
+left join
+(select sname,stype,sum(column16) as zhejiu 
+from sqmdb_cost.report80053 where period_type='M' and smonth between '202201' and '202206' group by sname,stype) b
+on a.sname=b.sname and a.stype=b.stype
+left join
+(select sname,stype,sum(column1)/10000 as cost_total 
+from sqmdb_cost.report50 where period_type='M' and smonth between '202201' and '202206' group by sname,stype) c
+on a.sname=c.sname and a.stype=c.stype
+where a.sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')

+ 32 - 0
Scripts/kpi31/07_city.sql

@@ -0,0 +1,32 @@
+--07、百元净资产网运成本
+---地市
+select 
+'202206' as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+a.sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'7' as ZB_CODE,
+'百元净资产网运成本' as ZB_NAME,
+'否' as IS_RATIO,
+c.cost_total as QZ_FZ,
+a.zichan-b.zhejiu as QZ_FM,
+c.cost_total/(a.zichan-b.zhejiu)*100 as BY_QZ
+from 
+(select sname,stype,sum(column7+column8)/2 as zichan 
+from sqmdb_cost.report80054 where period_type='M' and smonth between '202201' and '202206' group by sname,stype) a
+left join
+(select sname,stype,sum(column16) as zhejiu 
+from sqmdb_cost.report80053 where period_type='M' and smonth between '202201' and '202206' group by sname,stype) b
+on a.sname=b.sname and a.stype=b.stype
+left join
+(select sname,stype,sum(column1)/10000 as cost_total 
+from sqmdb_cost.report50 where period_type='M' and smonth between '202201' and '202206' group by sname,stype) c
+on a.sname=c.sname
+join 
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid) dg
+on a.sname=dg.city_pro
+where a.sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+order by dg.city_code

+ 19 - 0
Scripts/kpi31/08_b10.sql

@@ -0,0 +1,19 @@
+--08、网络能耗占收比
+---北10
+select 
+smonth as MONTH_ID,
+'北10' as ZB_TYPE,
+sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'8' as ZB_CODE,
+'网络能耗占收比' as ZB_NAME,
+'是' as IS_RATIO,
+column1 as QZ_FZ,--能耗成本,
+column5 as QZ_FM,--本年收入累计,
+column1/column5 as BY_QZ
+from sqmdb_cost.report50010 
+where sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202206'

+ 28 - 0
Scripts/kpi31/08_city.sql

@@ -0,0 +1,28 @@
+--08、网络能耗占收比
+---地市
+select 
+a.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+a.sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'8' as ZB_CODE,
+'网络能耗占收比' as ZB_NAME,
+'是' as IS_RATIO,
+a.cost_nenghao as QZ_FZ,
+b.income_year as QZ_FM,
+case when b.income_year=0 then null else a.cost_nenghao/b.income_year end as BY_QZ
+from
+(select '202206' as smonth,sname,stype,
+sum(column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115)/10000 as cost_nenghao
+from sqmdb_cost.report50 where period_type='M' and stype ='北方省汇总展现' and smonth between '202201' and '202206' group by sname,stype) a
+left join
+(select report_id,smonth,sname,stype,column4 as income_year from sqmdb_cost.report80040) b
+on a.smonth=b.smonth and a.sname=b.sname
+join 
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid) dg
+on a.sname=dg.city_pro
+where a.sname in ('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+order by dg.city_code

+ 23 - 0
Scripts/kpi31/09_b10.sql

@@ -0,0 +1,23 @@
+--09、百元资产修理维护费
+---北10
+select 
+t1.smonth as MONTH_ID,
+'北10' as ZB_TYPE,
+t1.sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'9' as ZB_CODE,
+'百元资产修理维护费' as ZB_NAME,
+'否' as IS_RATIO,
+t1.cost_fix as QZ_FZ,
+t2.zichan as QZ_FM,
+(t1.cost_fix/t2.zichan)*100 as BY_QZ
+from
+(select smonth,stype,sname,cost_fix from sqmdb_cost.chengben_shengnei where smonth='202206' and stype='北10') t1
+join
+(select sname,sum(column7+column8)/2 as zichan from sqmdb_cost.report80054 where period_type='M'
+and sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and stype='分省展现' and smonth between '202201' and '202206' group by sname) t2
+on t1.sname=t2.sname

+ 27 - 0
Scripts/kpi31/09_city.sql

@@ -0,0 +1,27 @@
+--09、百元资产修理维护费
+---地市
+select 
+t1.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+t1.sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'9' as ZB_CODE,
+'百元资产修理维护费' as ZB_NAME,
+'否' as IS_RATIO,
+t1.cost_fix as QZ_FZ,
+t2.zichan as QZ_FM,
+(t1.cost_fix/t2.zichan)*100 as BY_QZ
+from
+(select smonth,stype,sname,cost_fix from sqmdb_cost.chengben_shengnei where smonth='202206' and stype='地市') t1
+join
+(select sname,sum(column7+column8)/2 as zichan from sqmdb_cost.report80054 where period_type='M'
+and sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and smonth between '202201' and '202206' group by sname) t2
+on t1.sname=t2.sname
+join 
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid) dg
+on t1.sname=dg.city_pro
+order by dg.city_code

+ 20 - 0
Scripts/kpi31/10_b10.sql

@@ -0,0 +1,20 @@
+--10、修理维护费占收比(省内口径)
+select 
+cs.smonth as MONTH_ID,
+'北10' as ZB_TYPE,
+cs.sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'10' as ZB_CODE,
+'修理维护费占收比(省内口径)' as ZB_NAME,
+'是' as IS_RATIO,
+cs.cost_fix as QZ_FZ,
+r.column4 as QZ_FM,
+cs.cost_fix/r.column4 as BY_QZ
+from sqmdb_cost.chengben_shengnei cs
+join sqmdb_cost.report80040 r on cs.smonth=r.smonth and cs.sname=r.sname
+where r.period_type='M' 
+and cs.stype='北10'
+and cs.smonth='202206'

+ 25 - 0
Scripts/kpi31/10_city.sql

@@ -0,0 +1,25 @@
+--10、修理维护费占收比(省内口径)
+select 
+cs.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+cs.sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'10' as ZB_CODE,
+'修理维护费占收比(省内口径)' as ZB_NAME,
+'是' as IS_RATIO,
+cs.cost_fix as QZ_FZ,
+r.column4 as QZ_FM,
+cs.cost_fix/r.column4 as BY_QZ
+from sqmdb_cost.chengben_shengnei cs
+join sqmdb_cost.report80040 r on cs.smonth=r.smonth and cs.sname=r.sname
+join
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid) dg
+on cs.sname=dg.city_pro
+where r.period_type='M' 
+and cs.stype='地市'
+and cs.smonth='202206'
+order by dg.city_code
+

+ 38 - 0
Scripts/kpi31/11_city.sql

@@ -0,0 +1,38 @@
+--11、单业务量移网成本
+---地市
+select 
+cost_t.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+cost_t.city_code*100 as CITY_ID,
+cost_t.city_name as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'11' as ZB_CODE,
+'单业务量移网成本' as ZB_NAME,
+'否' as IS_RATIO,
+cost_t.cost_yw+cost_t.cost_hexin as QZ_FZ,
+ywl_t.yewul as QZ_FM,
+(cost_t.cost_yw+cost_t.cost_hexin)/ywl_t.yewul/7 as BY_QZ
+from 
+(select a.smonth,dg.city_name,dg.city_code,a.cost_yw,a.cost_hexin from
+(select '202207' as smonth,sname,
+sum(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18) as cost_yw,
+sum(column19+column20+column21+column22+column23+column24+column25+column26) as cost_hexin
+from sqmdb_cost.report50
+where period_type='M' 
+and sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and smonth between '202201' and '202207' group by sname) a
+join (select distinct city_code,city_pro,city_name from sqmdb_cost.dict_grid) dg 
+on a.sname=dg.city_pro) cost_t
+join
+(select dg.city_name,avg_num(y1.yewul,y2.yewul) as yewul from
+(select city_name,sum(yewul) as yewul from sqmdb_cost.zpzs z where grid_name!='合计' and smonth='202112' group by city_name) y1
+join
+(select city_name,sum(yewul) as yewul from sqmdb_cost.zpzs z where grid_name!='合计' and smonth='202207' group by city_name) y2
+on y1.city_name=y2.city_name
+join 
+(select distinct city_sname,city_code,city_name from sqmdb_cost.dict_grid) dg
+on y1.city_name=dg.city_sname) ywl_t
+on cost_t.city_name=ywl_t.city_name
+order by cost_t.city_code

+ 38 - 0
Scripts/kpi31/11_grid.sql

@@ -0,0 +1,38 @@
+--11、单业务量移网成本
+---网格
+select 
+cost_t.smonth as MONTH_ID,
+'网格' as ZB_TYPE,
+'河北' as PROV_NAME,
+dcg.city_code*100 as CITY_ID,
+dcg.city_name as CITY_NAME,
+dcg.grid_code as GRID_ID,
+dcg.grid_name as GRID_NAME,
+'11' as ZB_CODE,
+'单业务量移网成本' as ZB_NAME,
+'否' as IS_RATIO,
+cost_t.cost_yw+cost_t.cost_hexin as QZ_FZ,
+ywl_t.yewul as QZ_FM,
+(cost_t.cost_yw+cost_t.cost_hexin)/ywl_t.yewul/7 as BY_QZ
+from 
+(select a.smonth,a.city_name,a.grid_name,dgc.grid_code,a.cost_yw,a.cost_hexin from
+(select smonth,city_name_short(city_name) as city_name,grid_name,
+(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17+column18) as cost_yw,
+(column19+column20+column21+column22+column23+column24+column25+column26) as cost_hexin
+from sqmdb_cost.report49
+where period_type='Y' 
+and smonth='202207') a 
+join sqmdb_cost.dict_grid_code dgc 
+on a.city_name=dgc.city_name and trim(a.grid_name)=trim(dgc.grid_name)) cost_t
+join
+(select dg.city_name,dg.grid_code,dg.grid_name,avg_num(y1.yewul,y2.yewul) as yewul from
+(select city_name,grid_name,sum(yewul) as yewul from sqmdb_cost.zpzs z where grid_name!='合计' and smonth='202112' group by city_name,grid_name) y1
+join
+(select city_name,grid_name,sum(yewul) as yewul from sqmdb_cost.zpzs z where grid_name!='合计' and smonth='202207' group by city_name,grid_name) y2
+on y1.city_name=y2.city_name and trim(y1.grid_name)=trim(y2.grid_name)
+join sqmdb_cost.dict_grid_code dg
+on y1.city_name=dg.city_name and trim(y1.grid_name)=trim(dg.grid_name) 
+where dg.grid_code is not null and avg_num(y1.yewul,y2.yewul)>0) ywl_t
+on cost_t.grid_code=ywl_t.grid_code
+join sqmdb_cost.dict_code_grid dcg on cost_t.grid_code=dcg.grid_code 
+order by dcg.city_code 

+ 22 - 0
Scripts/kpi31/12_city.sql

@@ -0,0 +1,22 @@
+--12、单端口网运成本(月)
+---地市
+select 
+city.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+city.city_sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'12' as ZB_CODE,
+'单端口网运成本(月)' as ZB_NAME,
+'否' as IS_RATIO,
+city.cost_total as QZ_FZ,
+city.port_inuse as QZ_FM,
+city.cost_total/city.port_inuse/6 as BY_QZ
+from sqmdb_cost.rpt_dport_cost_city city
+left join
+(select distinct city_code,city_sname from sqmdb_cost.dict_grid) dg
+on city.city_sname=dg.city_sname
+where smonth='202206'
+order by dg.city_code

+ 19 - 0
Scripts/kpi31/12_grid.sql

@@ -0,0 +1,19 @@
+--12、单端口网运成本(月)
+---网格
+select 
+smonth as MONTH_ID,
+'网格' as ZB_TYPE,
+'河北' as PROV_NAME,
+city_code*100 as CITY_ID,
+city_name as CITY_NAME,
+grid_code as GRID_ID,
+grid_name as GRID_NAME,
+'12' as ZB_CODE,
+'单端口网运成本(月)' as ZB_NAME,
+'否' as IS_RATIO,
+cost_total as QZ_FZ,
+ftth_port_sts_count as QZ_FM,
+cost_port as BY_QZ
+from sqmdb_cost.rpt_dport_cost_grid
+where smonth='202206'
+order by city_code

+ 18 - 0
Scripts/kpi31/13_b10.sql

@@ -0,0 +1,18 @@
+--13、单端口能耗成本(月)
+---北10
+select 
+smonth as MONTH_ID,
+'北10' as ZB_TYPE,
+sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'13' as ZB_CODE,
+'单端口能耗成本(月)' as ZB_NAME,
+'否' as IS_RATIO,
+cost_nenghao as QZ_FZ,
+port_inuse as QZ_FM,
+cost_nenghao/port_inuse/6 as BY_QZ
+from sqmdb_cost.rpt_dport_cost_b10
+where smonth='202206'

+ 22 - 0
Scripts/kpi31/13_city.sql

@@ -0,0 +1,22 @@
+--13、单端口能耗成本(月)
+---地市
+select 
+city.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+city.city_sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'13' as ZB_CODE,
+'单端口能耗成本(月)' as ZB_NAME,
+'否' as IS_RATIO,
+city.cost_nenghao as QZ_FZ,
+city.port_inuse as QZ_FM,
+city.cost_nenghao/city.port_inuse/6 as BY_QZ
+from sqmdb_cost.rpt_dport_cost_city city
+left join
+(select distinct city_code,city_sname from sqmdb_cost.dict_grid) dg
+on city.city_sname=dg.city_sname
+where smonth='202206'
+order by dg.city_code

+ 20 - 0
Scripts/kpi31/13_grid.sql

@@ -0,0 +1,20 @@
+--13、单端口能耗成本(月)
+---网格
+select 
+smonth as MONTH_ID,
+'网格' as ZB_TYPE,
+'河北' as PROV_NAME,
+city_code*100 as CITY_ID,
+city_name as CITY_NAME,
+grid_code as GRID_ID,
+grid_name as GRID_NAME,
+'13' as ZB_CODE,
+'单端口能耗成本(月)' as ZB_NAME,
+'否' as IS_RATIO,
+cost_nenghao as QZ_FZ,
+ftth_port_sts_count as QZ_FM,
+cost_port_nenghao as BY_QZ
+from sqmdb_cost.rpt_dport_cost_grid
+where smonth='202206'
+order by city_code
+

+ 18 - 0
Scripts/kpi31/14_b10.sql

@@ -0,0 +1,18 @@
+--14、单载频载扇能耗(月)
+---北10
+select 
+smonth as MONTH_ID,
+'北10' as ZB_TYPE,
+sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'14' as ZB_CODE,
+'单载频载扇能耗(月)' as ZB_NAME,
+'否' as IS_RATIO,
+cost_yw+cost_hexin as QZ_FZ,
+zps_num_no5g as QZ_FM,
+case when zps_num_no5g=0 then 0 else (cost_yw+cost_hexin)/zps_num_no5g/6 end as BY_QZ
+from sqmdb_cost.rpt_dzpzs_cost_b10 
+where smonth='202206'

+ 19 - 0
Scripts/kpi31/14_city.sql

@@ -0,0 +1,19 @@
+--14、单载频载扇能耗(月)
+---地市
+select 
+smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+city_code as CITY_ID,
+city_sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'14' as ZB_CODE,
+'单载频载扇能耗(月)' as ZB_NAME,
+'否' as IS_RATIO,
+cost_yw+cost_hexin as QZ_FZ,
+zps_num_with5g as QZ_FM,
+case when zps_num_with5g=0 then 0 else (cost_yw+cost_hexin)/zps_num_with5g/6 end as BY_QZ
+from sqmdb_cost.rpt_dzpzs_cost_city 
+where smonth='202206'
+order by city_code

+ 18 - 0
Scripts/kpi31/14_grid.sql

@@ -0,0 +1,18 @@
+--14、单载频载扇能耗(月)
+---网格
+select 
+smonth as MONTH_ID,
+'网格' as ZB_TYPE,
+'河北' as PROV_NAME,
+city_code*100 as CITY_ID,
+city_name as CITY_NAME,
+grid_code as GRID_ID,
+grid_name as GRID_NAME,
+'14' as ZB_CODE,
+'单载频载扇能耗(月)' as ZB_NAME,
+'否' as IS_RATIO,
+cost_yw+cost_hexin as QZ_FZ,
+zps_num_with5g as QZ_FM,
+cost_zps_with5g as BY_QZ
+from sqmdb_cost.rpt_dzpzs_cost_grid grid
+where smonth='202206'

+ 37 - 0
Scripts/kpi31/15_city.sql

@@ -0,0 +1,37 @@
+--15、活动ONU单端口能耗(月)
+---地市
+select 
+t1.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+t1.city_code*100 as CITY_ID,
+t1.city_name as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'15' as ZB_CODE,
+'活动ONU单端口能耗(月)' as ZB_NAME,
+'否' as IS_RATIO,
+t1.cost_nenghao/10000 as QZ_FZ,
+t2.active_onu_num/10000 as QZ_FM,
+t1.cost_nenghao/t2.active_onu_num/6 as BY_QZ
+from 
+(select a.smonth,dg.city_code,dg.city_name,a.cost_nenghao from
+(select '202206' as smonth,sname,
+sum((column5+column19+column27+column41+column49+column57+column70+column78+column86+column94+column100+column108+column115)-column5-column19-column108) as cost_nenghao
+from sqmdb_cost.report50 r
+where period_type='M' and stype ='北方省汇总展现'
+and sname in ('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and smonth between '202201' and '202206' group by sname) a
+join (select distinct city_code,city_name,city_pro from sqmdb_cost.dict_grid) dg
+on a.sname=dg.city_pro) t1
+join
+(select n2.smonth,n2.city_name,
+avg_num(n1.active_onu_num,n2.active_onu_num) as active_onu_num from
+(select * from sqmdb_cost.active_onu where smonth='202112') n1
+join 
+(select * from sqmdb_cost.active_onu where smonth='202206') n2
+on n1.city_name=n2.city_name) t2
+on t1.city_name=t2.city_name
+order by t1.city_code
+
+

+ 19 - 0
Scripts/kpi31/16_b10.sql

@@ -0,0 +1,19 @@
+--16、单站铁塔租赁费(月)
+---北10数据(select * from sqmdb_cost.report50016)
+select 
+smonth as MONTH_ID,
+'北10' as ZB_TYPE,
+sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'16' as ZB_CODE,
+'单站铁塔租赁费(月)' as ZB_NAME,
+'否' as IS_RATIO,
+column2*10000 as QZ_FZ,
+column5 as QZ_FM,
+column2*10000/column5/6 as BY_QZ
+from sqmdb_cost.report50016
+where sname in ('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and smonth='202206'

+ 22 - 0
Scripts/kpi31/16_city.sql

@@ -0,0 +1,22 @@
+--16、单站铁塔租赁费(月)
+---地市
+select 
+c.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+c.city_name as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'16' as ZB_CODE,
+'单站铁塔租赁费(月)' as ZB_NAME,
+'否' as IS_RATIO,
+c.tower_cost as QZ_FZ,
+c.tower_num_avg as QZ_FM,
+(c.tower_cost/c.tower_num_avg)/6 as BY_QZ
+from sqmdb_cost.rpt_tower_cost_city c
+left join
+(select distinct city_code,city_sname from sqmdb_cost.dict_grid) dg
+on c.city_name=dg.city_sname
+where smonth='202206'
+order by dg.city_code

+ 18 - 0
Scripts/kpi31/16_grid.sql

@@ -0,0 +1,18 @@
+--16、单站铁塔租赁费(月)
+---网格
+select 
+smonth as MONTH_ID,
+'网格' as ZB_TYPE,
+'河北' as PROV_NAME,
+city_code*100 as CITY_ID,
+city_name as CITY_NAME,
+grid_code as GRID_ID,
+grid_name as GRID_NAME,
+'16' as ZB_CODE,
+'单站铁塔租赁费(月)' as ZB_NAME,
+'否' as IS_RATIO,
+tower_cost as QZ_FZ,
+tower_num_avg as QZ_FM,
+tower_cost_avg as BY_QZ
+from sqmdb_cost.rpt_tower_cost_grid
+where smonth='202206'

+ 29 - 0
Scripts/kpi31/17_city.sql

@@ -0,0 +1,29 @@
+--17、户均装机料费
+---地市
+select 
+fz.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+fm.city_code*100 as CITY_ID,
+fz.sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'17' as ZB_CODE,
+'户均装机料费' as ZB_NAME,
+'否' as IS_RATIO,
+fz.cost_liao as QZ_FZ,
+fm.order_num as QZ_FM,
+fz.cost_liao/fm.order_num/6 as BY_QZ
+from
+(select smonth,sname,cost_liao from sqmdb_cost.chengben_shengnei cs
+where stype='地市' and smonth='202206') fz
+join
+(select b.city_code,b.city_pro,a.order_num from
+(select smonth,city_name,sum(order_num)/10000 as order_num 
+from sqmdb_cost.zhuangji z where smonth='202206'
+group by smonth,city_name) a
+join
+(select distinct city_code,city_name,city_pro from sqmdb_cost.dict_grid dg) b
+on a.city_name=b.city_name) fm
+on fz.sname=fm.city_pro
+order by fm.city_code

+ 29 - 0
Scripts/kpi31/17_grid.sql

@@ -0,0 +1,29 @@
+--17、户均装机料费(集团网格report49料费成本大部分是0,都集中在市本部)
+---网格
+select 
+fz.smonth as MONTH_ID,
+'网格' as ZB_TYPE,
+'河北' as PROV_NAME,
+dcg.city_code*100 as CITY_ID,
+dcg.city_name as CITY_NAME,
+dcg.grid_code as GRID_ID,
+fz.grid_name as GRID_NAME,
+'17' as ZB_CODE,
+'户均装机料费' as ZB_NAME,
+fz.cost_liao as QZ_FZ,
+fm.order_num as QZ_FM,
+fz.cost_liao/fm.order_num/4 as BY_QZ
+from
+(select a.smonth,a.city_name,a.grid_name,a.cost_liao,dgc.grid_code from
+(select smonth,city_name_short(city_name) as city_name,grid_name,column33 as cost_liao
+from sqmdb_cost.report49 where period_type='Y' and smonth='202204') a
+join sqmdb_cost.dict_grid_code dgc on a.city_name=dgc.city_name and trim(a.grid_name)=trim(dgc.grid_name)
+where dgc.grid_code is not null) fz
+join
+(select b.smonth,b.city_name,b.area_name,b.order_num,dgc1.grid_code from
+(select smonth,city_name_short(city_name) as city_name,area_name,sum(order_num) as order_num 
+from sqmdb_cost.zhuangji where smonth='202204' group by smonth,city_name_short(city_name),area_name) b
+join sqmdb_cost.dict_grid_code dgc1 on b.city_name=dgc1.city_name and trim(b.area_name)=trim(dgc1.grid_name)) fm
+on fz.grid_code=fm.grid_code
+join sqmdb_cost.dict_code_grid dcg on fz.grid_code=dcg.grid_code 
+

+ 25 - 0
Scripts/kpi31/18_b10.sql

@@ -0,0 +1,25 @@
+--18、单皮长公里线路维护费(月)
+---北10
+select 
+t1.smonth as MONTH_ID,
+'北10' as ZB_TYPE,
+t1.sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'18' as ZB_CODE,
+'单皮长公里线路维护费(月)' as ZB_NAME,
+'否' as IS_RATIO,
+t1.cost_xianlu as QZ_FZ,
+t2.total_gl as QZ_FM,
+t1.cost_xianlu/t2.total_gl/6 as BY_QZ
+from
+(select '202206' as smonth,sname,
+sum(column65+column66+column67+column68+column69)/10000 as cost_xianlu
+from sqmdb_cost.report50
+where sname in ('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')
+and period_type='M' and smonth between '202201' and '202206' group by sname) t1
+join
+(select sname,total_gl from sqmdb_cost.jt_number_b10 where smonth='202206') t2
+on t1.sname=t2.sname

+ 30 - 0
Scripts/kpi31/18_city.sql

@@ -0,0 +1,30 @@
+--18、单皮长公里线路维护费(月)
+---地市
+select 
+t1.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+t1.sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'18' as ZB_CODE,
+'单皮长公里线路维护费(月)' as ZB_NAME,
+'否' as IS_RATIO,
+t1.cost_xianlu as QZ_FZ,
+t2.total_gl as QZ_FM,
+t1.cost_xianlu/t2.total_gl/6 as BY_QZ
+from
+(select '202206' as smonth,sname,
+sum(column65+column66+column67+column68+column69)/10000 as cost_xianlu
+from sqmdb_cost.report50
+where sname in('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+and period_type='M' and smonth between '202201' and '202206' group by sname) t1
+join
+(select city_name||'_河北' as city_pro,total_gl 
+from sqmdb_cost.jt_number_city where month_id='202206') t2
+on t1.sname=t2.city_pro
+join 
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid) dg
+on t1.sname=dg.city_pro
+order by dg.city_code

+ 24 - 0
Scripts/kpi31/19_b10.sql

@@ -0,0 +1,24 @@
+--19、无线成本占收比
+---北10
+select 
+a.smonth as MONTH_ID,
+'北10' as ZB_TYPE,
+a.sname as PROV_NAME,
+null as CITY_ID,
+null as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'19' as ZB_CODE,
+'无线成本占收比' as ZB_NAME,
+'是' as IS_RATIO,
+a.cost_wireless as QZ_FZ,
+b.income_year as QZ_FM,
+case when b.income_year=0 then null else a.cost_wireless/b.income_year end as BY_QZ
+from
+(select '202206' as smonth,sname,stype,
+sum(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17)/10000 as cost_wireless --column18 账面人工成本
+from sqmdb_cost.report50 where period_type='M' and smonth between '202201' and '202206' group by sname,stype) a
+left join
+(select report_id,smonth,sname,stype,column4 as income_year from sqmdb_cost.report80040 where smonth='202206') b
+on a.sname=b.sname
+where a.sname in('北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南')

+ 29 - 0
Scripts/kpi31/19_city.sql

@@ -0,0 +1,29 @@
+--19、无线成本占收比
+---地市
+select 
+a.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+a.sname as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'19' as ZB_CODE,
+'无线成本占收比' as ZB_NAME,
+'是' as IS_RATIO,
+a.cost_wireless as QZ_FZ,
+b.income_year as QZ_FM,
+case when b.income_year=0 then null else a.cost_wireless/b.income_year end as BY_QZ
+from
+(select '202206' as smonth,sname,
+sum(column2+column3+column4+column5+column6+column7+column8+column9+column10+column11+column12+column13+column14+column15+column16+column17)/10000 as cost_wireless --column18 账面人工成本
+from sqmdb_cost.report50 where period_type='M' and stype ='北方省汇总展现' 
+and smonth between '202201' and '202206' group by sname) a
+left join
+(select report_id,smonth,sname,stype,column4 as income_year from sqmdb_cost.report80040 where smonth='202206') b
+on a.sname=b.sname
+join 
+(select distinct city_code,city_pro from sqmdb_cost.dict_grid) dg
+on a.sname=dg.city_pro
+where a.sname in ('石家庄_河北','唐山_河北','秦皇岛_河北','邯郸_河北','邢台_河北','保定_河北','张家口_河北','承德_河北','廊坊_河北','沧州_河北','衡水_河北','雄安_河北')
+order by dg.city_code

+ 28 - 0
Scripts/kpi31/20_city.sql

@@ -0,0 +1,28 @@
+--20、PUE超标率
+---地市
+select
+'202206' as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+a.city_name as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'20' as ZB_CODE,
+'PUE超标率' as ZB_NAME,
+'是' as IS_RATIO,
+pue_total as QZ_FZ,
+pue_over as QZ_FM,
+pue_over_rate as BY_QZ
+from
+(select 
+case when city_name='雄安新区' then '雄安' else city_name end,
+count(*) as pue_total,
+sum(case when pue>1.5 then 1 else 0 end) as pue_over,
+sum(case when pue>1.5 then 1 else 0 end)/count(*)::numeric as pue_over_rate
+from sqmdb_cost.pue_top 
+group by city_name) a
+join 
+(select distinct city_code,city_sname from sqmdb_cost.dict_grid) dg
+on a.city_name=dg.city_sname
+order by dg.city_code

+ 26 - 0
Scripts/kpi31/20_grid.sql

@@ -0,0 +1,26 @@
+--20、PUE超标率
+---网格
+select
+'202206' as MONTH_ID,
+'网格' as ZB_TYPE,
+'河北' as PROV_NAME,
+dcg.city_code*100 as CITY_ID,
+a.city_name as CITY_NAME,
+dcg.grid_code as GRID_ID,
+a.area_name as GRID_NAME,
+'20' as ZB_CODE,
+'PUE超标率' as ZB_NAME,
+'是' as IS_RATIO,
+a.pue_over as QZ_FZ,
+a.pue_total as QZ_FM,
+a.pue_over_rate as BY_QZ
+from
+(select city_name_short(city_name) as city_name,area_name,
+count(*) as pue_total,
+sum(case when pue>1.5 then 1 else 0 end) as pue_over,
+sum(case when pue>1.5 then 1 else 0 end)/count(*)::numeric as pue_over_rate
+from sqmdb_cost.pue_top 
+group by city_name,area_name) a
+join sqmdb_cost.dict_grid_code dgc on a.city_name=dgc.city_name and trim(a.area_name)=trim(dgc.grid_name)
+join sqmdb_cost.dict_code_grid dcg on dgc.grid_code=dcg.grid_code 
+order by dcg.city_code

+ 28 - 0
Scripts/kpi31/21_city.sql

@@ -0,0 +1,28 @@
+--21、转供电占比
+---地市(可由网格数据汇聚)
+select 
+a.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+a.city_name as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'21' as ZB_CODE,
+'转供电占比' as ZB_NAME,
+'是' as IS_RATIO,
+zgd_num as QZ_FZ,
+total_num as QZ_FM,
+zgd_rate as BY_QZ
+from
+(select smonth,city_name,
+count(*) as total_num,
+sum(case when y.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end) as zgd_num,
+sum(case when y.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end)/count(*)::numeric as zgd_rate
+from sqmdb_cost.ytmx_new y 
+where build_type_name not in ('办公楼','办公用房','营业用房') and smonth='202206'
+group by smonth,city_name) a
+join 
+(select distinct city_code,city_name from sqmdb_cost.dict_grid) dg
+on a.city_name=dg.city_name
+order by dg.city_code

+ 29 - 0
Scripts/kpi31/21_grid.sql

@@ -0,0 +1,29 @@
+--21、转供电占比
+---网格
+select 
+a.smonth as MONTH_ID,
+'网格' as ZB_TYPE,
+'河北' as PROV_NAME,
+dcg.city_code*100 as CITY_ID,
+dcg.city_name as CITY_NAME,
+dcg.grid_code as GRID_ID,
+dcg.grid_name as GRID_NAME,
+'21' as ZB_CODE,
+'转供电占比' as ZB_NAME,
+'是' as IS_RATIO,
+a.zgd_num as QZ_FZ,
+a.total_num as QZ_FM,
+a.zgd_rate as BY_QZ
+from
+(select yn.smonth,dgc.grid_code,
+count(*) as total_num,
+sum(case when yn.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end) as zgd_num,
+sum(case when yn.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end)/count(*)::numeric as zgd_rate
+from sqmdb_cost.ytmx_new yn
+join sqmdb_cost.dict_grid_code dgc 
+on city_name_short(yn.city_name)=dgc.city_name and trim(yn.area_name)=trim(dgc.grid_name)
+where yn.build_type_name not in ('办公楼','办公用房','营业用房') and yn.smonth='202206'
+group by yn.smonth,dgc.grid_code) a
+join sqmdb_cost.dict_code_grid dcg on a.grid_code=dcg.grid_code
+order by dcg.city_code
+

+ 29 - 0
Scripts/kpi31/22_city.sql

@@ -0,0 +1,29 @@
+--22、超高电价占比
+---地市(可由网格数据汇聚)
+select 
+a.smonth as MONTH_ID,
+'地市' as ZB_TYPE,
+'河北' as PROV_NAME,
+dg.city_code*100 as CITY_ID,
+a.city_name as CITY_NAME,
+null as GRID_ID,
+null as GRID_NAME,
+'22' as ZB_CODE,
+'超高电价占比' as ZB_NAME,
+'是' as IS_RATIO,
+a.high_price_num as QZ_FZ,
+a.total_num as QZ_FM,
+a.high_price_rate as BY_QZ
+from
+(select smonth,city_name,
+count(*) as total_num,
+sum(case when y.eprice>0.8 then 1 else 0 end) as high_price_num,
+sum(case when y.eprice>0.8 then 1 else 0 end)/count(*)::numeric as high_price_rate
+from 
+(select *,(case when accrued_power=0 then 0 else accrued_cost/accrued_power end) as eprice 
+from sqmdb_cost.ytmx_new where build_type_name not in ('办公楼','办公用房','营业用房') and smonth='202207') y 
+group by smonth,city_name) a
+join 
+(select distinct city_code,city_name from sqmdb_cost.dict_grid) dg
+on a.city_name=dg.city_name
+order by dg.city_code

この差分においてかなりの量のファイルが変更されているため、一部のファイルを表示していません