成本占比地市维度.sql 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. --1能耗缺少成本中心占比
  2. select
  3. smonth as "月份",
  4. city_name as "地市",
  5. has_num as "有成本中心局站数",
  6. no_num as "无成本中心局站数",
  7. total_num as "局站总数",
  8. err_rate as "能耗系统无成本中心局站占比"
  9. from
  10. (select
  11. t1.*,
  12. case when t1.city_name='未知地市' then 15 else coalesce(dc.sort_id,14) end as sort_id
  13. from
  14. (select smonth,
  15. coalesce(city_name_short(city_name),'未知地市') as city_name,
  16. sum(case when cost_unit_name is not null then 1 else 0 end) as has_num,
  17. sum(case when cost_unit_name is null then 1 else 0 end) as no_num,
  18. count(*) as total_num,
  19. round(sum(case when cost_unit_name is null then 1 else 0 end)/count(*)::numeric,4) as err_rate
  20. from sqmdb_cost.ytmx_new where smonth='202207'
  21. group by smonth,city_name)t1
  22. left join dict_city dc on t1.city_name=dc.city_name
  23. union all
  24. select smonth,'全省' as city_name,
  25. sum(case when cost_unit_name is not null then 1 else 0 end) as has_num,
  26. sum(case when cost_unit_name is null then 1 else 0 end) as no_num,
  27. count(*) as total_num,
  28. round(sum(case when cost_unit_name is null then 1 else 0 end)/count(*)::numeric,4) as err_rate,
  29. 16 as sort_id
  30. from sqmdb_cost.ytmx_new where smonth='202207'
  31. group by smonth) a
  32. order by sort_id
  33. --2既租铁塔又租三方局站占比
  34. select
  35. smonth as "月份",
  36. city_name as "地市",
  37. zu_tw_num as "租用铁塔局站数",
  38. zu_3rd_num as "租用三方局站数",
  39. err_num as "既租铁塔又租三方局站数",
  40. total_num as "局站总数",
  41. err_rate as "既租铁塔又租三方局站占比"
  42. from
  43. (select
  44. smonth,city_name_short(city_name) as city_name,
  45. coalesce(sort_id_city,15) as sort_id_city,
  46. sum(case when zulin_type='租用铁塔' then 1 else 0 end) as zu_tw_num,
  47. sum(case when zulin_type='租用第三方' then 1 else 0 end) as zu_3rd_num,
  48. sum(case when zulin_type='租用铁塔+租用第三方' then 1 else 0 end) as err_num,
  49. count(*) as total_num,
  50. round(sum(case when zulin_type='租用铁塔+租用第三方' then 1 else 0 end)/count(*)::numeric,4) as err_rate
  51. from sqmdb_cost.err_station_has_tw_3rd
  52. group by smonth,city_name,sort_id_city
  53. union all
  54. select smonth,'全省' as city_name,16 as sort_id_city,
  55. sum(case when zulin_type='租用铁塔' then 1 else 0 end) as zu_tw_num,
  56. sum(case when zulin_type='租用第三方' then 1 else 0 end) as zu_3rd_num,
  57. sum(case when zulin_type='租用铁塔+租用第三方' then 1 else 0 end) as err_num,
  58. count(*) as total_num,
  59. round(sum(case when zulin_type='租用铁塔+租用第三方' then 1 else 0 end)/count(*)::numeric,4) as err_rate
  60. from sqmdb_cost.err_station_has_tw_3rd
  61. group by smonth)a
  62. order by sort_id_city
  63. --3有合同无局站占比
  64. select
  65. smonth as "月份",
  66. city_name as "地市",
  67. has_num as "有合同有局站",
  68. no_num as "有合同无局站",
  69. total_num as "合同总数",
  70. err_rate as "有合同无局站占比"
  71. from
  72. (select
  73. smonth,city_name,coalesce(sort_id_city,15) as sort_id_city,
  74. sum(case when stype='有合同有局站' then 1 else 0 end) as has_num,
  75. sum(case when stype!='有合同有局站' then 1 else 0 end) as no_num,
  76. count(*) as total_num,
  77. round(sum(case when stype!='有合同有局站' then 1 else 0 end)/count(*)::numeric,4) as err_rate
  78. from sqmdb_cost.err_has_ht_no_station
  79. group by smonth,city_name,sort_id_city
  80. union all
  81. select smonth,'全省' as city_name,16 as sort_id_city,
  82. sum(case when stype='有合同有局站' then 1 else 0 end) as has_num,
  83. sum(case when stype!='有合同有局站' then 1 else 0 end) as no_num,
  84. count(*) as total_num,
  85. round(sum(case when stype!='有合同有局站' then 1 else 0 end)/count(*)::numeric,4) as err_rate
  86. from sqmdb_cost.err_has_ht_no_station
  87. group by smonth)a
  88. order by sort_id_city
  89. --4有能耗无局站占比
  90. select
  91. smonth as "月份",
  92. city_name as "地市",
  93. has_num as "有能耗有局站",
  94. no_num as "有能耗无局站",
  95. total_num as "能耗系统总数",
  96. err_rate as "有能耗无局站占比"
  97. from
  98. (select
  99. smonth,coalesce(city_name_short(city_name),'未知地市') as city_name,
  100. case when city_name is null then 15 else coalesce(sort_id_city,14) end as sort_id_city,
  101. sum(case when stype!='有能耗无索引' then 1 else 0 end) as has_num,
  102. sum(case when stype='有能耗无索引' then 1 else 0 end) as no_num,
  103. count(*) as total_num,
  104. round(sum(case when stype='有能耗无索引' then 1 else 0 end)/count(*)::numeric,4) as err_rate
  105. from sqmdb_cost.err_has_nh_no_station
  106. group by smonth,city_name,sort_id_city
  107. union all
  108. select smonth,'全省' as city_name,16 as sort_id_city,
  109. sum(case when stype!='有能耗无索引' then 1 else 0 end) as has_num,
  110. sum(case when stype='有能耗无索引' then 1 else 0 end) as no_num,
  111. count(*) as total_num,
  112. round(sum(case when stype='有能耗无索引' then 1 else 0 end)/count(*)::numeric,4) as err_rate
  113. from sqmdb_cost.err_has_nh_no_station
  114. group by smonth)a
  115. order by sort_id_city
  116. --5有45G实时能耗无设备占比
  117. --5能耗系统无关联网管能耗占比
  118. select
  119. smonth as "月份",
  120. city_name as "地市",
  121. has_num as "能耗系统有关联网管能耗局站",
  122. no_num as "能耗系统无关联网管能耗局站",
  123. total_num as "能耗系统总数",
  124. err_rate as "能耗系统无关联网管能耗局站占比"
  125. from
  126. (select
  127. smonth,coalesce(city_name_short(city_name),'未知地市') as city_name,
  128. case when city_name is null then 15 else coalesce(sort_id_city,14) end as sort_id_city,
  129. sum(case when stype='校验正常' then 1 else 0 end) as has_num,
  130. sum(case when stype!='校验正常' then 1 else 0 end) as no_num,
  131. count(*) as total_num,
  132. round(sum(case when stype!='校验正常' then 1 else 0 end)/count(*)::numeric,4) as err_rate
  133. from sqmdb_cost.err_has_nh_no_station
  134. group by smonth,city_name,sort_id_city
  135. union all
  136. select smonth,'全省' as city_name,16 as sort_id_city,
  137. sum(case when stype='校验正常' then 1 else 0 end) as has_num,
  138. sum(case when stype!='校验正常' then 1 else 0 end) as no_num,
  139. count(*) as total_num,
  140. round(sum(case when stype!='校验正常' then 1 else 0 end)/count(*)::numeric,4) as err_rate
  141. from sqmdb_cost.err_has_nh_no_station
  142. group by smonth)a
  143. order by sort_id_city
  144. --6高能耗站点占比
  145. select
  146. smonth as "月份",
  147. city_name as "地市",
  148. over_num_power as "高电量站点数",
  149. over_num_cost as "高电费站点数",
  150. total_num as "能耗系统总数",
  151. round((over_num_power+over_num_cost)/total_num::numeric,4) as "高能耗站点占比"
  152. from
  153. (select
  154. o1.*,o2.over_num_cost
  155. from
  156. (select
  157. smonth,coalesce(city_name_short(city_sname),'未知地市') as city_name,
  158. case when city_sname is null then 15 else coalesce(sort_id_city,14) end as sort_id_city,
  159. sum(case when over_lilun_power>=2.5 then 1 else 0 end) as over_num_power,
  160. count(*) as total_num
  161. from sqmdb_cost.rpt_baobiao_6_cgnh
  162. where smonth='202207' and lilun_power>1000
  163. group by smonth,city_sname,sort_id_city) o1
  164. left join
  165. (select
  166. smonth,coalesce(city_name_short(city_sname),'未知地市') as city_name,
  167. case when city_sname is null then 15 else coalesce(sort_id_city,14) end as sort_id_city,
  168. sum(case when over_lilun_cost>=3.5 then 1 else 0 end) as over_num_cost,
  169. count(*) as total_num
  170. from sqmdb_cost.rpt_baobiao_6_cgnh
  171. where smonth='202207' and lilun_power>1000 and over_lilun_power<2.5
  172. group by smonth,city_sname,sort_id_city) o2
  173. on o1.smonth=o2.smonth and o1.city_name=o2.city_name and o1.sort_id_city=o2.sort_id_city
  174. union all
  175. select
  176. o1.*,o2.over_num_cost
  177. from
  178. (select
  179. smonth,'全省' as city_name,16 sort_id_city,
  180. sum(case when over_lilun_power>=2.5 then 1 else 0 end) as over_num_power,
  181. count(*) as total_num
  182. from sqmdb_cost.rpt_baobiao_6_cgnh
  183. where smonth='202207' and lilun_power>1000
  184. group by smonth) o1
  185. left join
  186. (select
  187. smonth,'全省' as city_name,16 as sort_id_city,
  188. sum(case when over_lilun_cost>=3.5 then 1 else 0 end) as over_num_cost,
  189. count(*) as total_num
  190. from sqmdb_cost.rpt_baobiao_6_cgnh
  191. where smonth='202207' and lilun_power>1000 and over_lilun_power<2.5
  192. group by smonth) o2
  193. on o1.smonth=o2.smonth and o1.city_name=o2.city_name and o1.sort_id_city=o2.sort_id_city)a
  194. order by sort_id_city
  195. --7高租费站点占比(相同场景下)
  196. select
  197. smonth as "月份",
  198. city_sname as "地市",
  199. over_tower_num as "高铁塔租费局站数",
  200. over_hetong_num as "高合同租金局站数",
  201. (over_tower_num+over_hetong_num) as "高租费局站数",
  202. total_num as "局站总数",
  203. round((over_tower_num+over_hetong_num)/total_num::numeric,4) as "高租费局站占比"
  204. from(
  205. select
  206. smonth,city_sname,sort_id_city,
  207. sum(case when tower_cost_grid_scene_bs>1.5 then 1 else 0 end) as over_tower_num,--铁塔租费大于本场景铁塔租费均值
  208. sum(case when ht_cost_grid_scene_bs>1.5 then 1 else 0 end) as over_hetong_num,--合同租金大于本场景合同租金均值
  209. count(*) as total_num
  210. from sqmdb_cost.rpt_baobiao_4_cgzf rbc
  211. where smonth='202207'
  212. group by smonth,city_sname,sort_id_city) a
  213. order by sort_id_city
  214. --8超高租费站点占比(相同场景下)
  215. select
  216. smonth as "月份",
  217. city_sname as "地市",
  218. over_tower_num as "超高铁塔租费局站数",
  219. over_hetong_num as "超高合同租金局站数",
  220. (over_tower_num+over_hetong_num) as "超高租费局站数",
  221. total_num as "局站总数",
  222. round((over_tower_num+over_hetong_num)/total_num::numeric,4) as "超高租费局站占比"
  223. from(
  224. select
  225. smonth,city_sname,sort_id_city,
  226. sum(case when tower_cost_grid_scene_bs>2 then 1 else 0 end) as over_tower_num,--铁塔租费大于本场景铁塔租费均值
  227. sum(case when ht_cost_grid_scene_bs>2 then 1 else 0 end) as over_hetong_num,--合同租金大于本场景合同租金均值
  228. count(*) as total_num
  229. from sqmdb_cost.rpt_baobiao_4_cgzf rbc
  230. where smonth='202207'
  231. group by smonth,city_sname,sort_id_city) a
  232. order by sort_id_city