zwjs_cb_jt_grid.sql 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --集团(网格)
  2. select
  3. m_cm.smonth as "date",
  4. m_cm.prov_name as province_name,
  5. city_name_short(m_cm.city_name) as city_name,
  6. dc.city_code,
  7. m_cm.grid_name,
  8. dgc.grid_code,
  9. m_cm.kpi_name as index_name,
  10. m_cm.kpi_code as index_id,
  11. '万元' as index_unit,
  12. m_cm.prov_value as this_month,
  13. m_lm.prov_value as last_month,
  14. (m_cm.prov_value::numeric-m_lm.prov_value::numeric) as month_on_month,
  15. case when m_lm.prov_value::numeric=0 then 0 else (m_cm.prov_value::numeric-m_lm.prov_value::numeric)/m_lm.prov_value::numeric end as month_on_month_grow,
  16. y_cm.prov_value as this_year,
  17. y_lm.prov_value as last_year,
  18. (y_cm.prov_value::numeric-y_lm.prov_value::numeric) as year_on_year,
  19. case when y_lm.prov_value::numeric=0 then 0 else (y_cm.prov_value::numeric-y_lm.prov_value::numeric)/y_lm.prov_value::numeric end as year_on_year_grow
  20. from
  21. (select smonth,prov_name,city_name,grid_name,
  22. regexp_split_to_table(concat_ws('~','网运成本合计 ','1.修理费 ','(1)维保 ','(2)代维 ','(3)网优 ','(4)耗材 ','(5)修理 ','2.能耗成本 ','3.铁塔电费 ','4.铁塔租费 ','5.租赁费 ','6.客户接入工料 ','7.客户端 ','8.频率占用费 ','9.紧密型外包成本','10.其他 '),'~') kpi_name,
  23. regexp_split_to_table(concat_ws('~','JT_CB_001','JT_CB_002','JT_CB_003','JT_CB_004','JT_CB_005','JT_CB_006','JT_CB_007','JT_CB_008','JT_CB_009','JT_CB_010','JT_CB_011','JT_CB_012','JT_CB_013','JT_CB_014','JT_CB_015','JT_CB_016'),'~') kpi_code,
  24. regexp_split_to_table(concat_ws('~',cost_total,cost_fix_total,cost_fix_1_wb,cost_fix_2_dw,cost_fix_3_wy,cost_fix_4_hc,cost_fix_5_xl,cost_nenghao,cost_tower_elec,cost_tower_zu,cost_zulin,cost_liao,cost_client,cost_freq,cost_waibao,cost_other),'~')::numeric prov_value
  25. from sqmdb_cost.chengben_jt_month where stype='网格' and smonth='202207') m_cm --本月
  26. join
  27. (select smonth,prov_name,city_name,grid_name,
  28. regexp_split_to_table(concat_ws('~','网运成本合计 ','1.修理费 ','(1)维保 ','(2)代维 ','(3)网优 ','(4)耗材 ','(5)修理 ','2.能耗成本 ','3.铁塔电费 ','4.铁塔租费 ','5.租赁费 ','6.客户接入工料 ','7.客户端 ','8.频率占用费 ','9.紧密型外包成本','10.其他 '),'~') kpi_name,
  29. regexp_split_to_table(concat_ws('~','JT_CB_001','JT_CB_002','JT_CB_003','JT_CB_004','JT_CB_005','JT_CB_006','JT_CB_007','JT_CB_008','JT_CB_009','JT_CB_010','JT_CB_011','JT_CB_012','JT_CB_013','JT_CB_014','JT_CB_015','JT_CB_016'),'~') kpi_code,
  30. regexp_split_to_table(concat_ws('~',cost_total,cost_fix_total,cost_fix_1_wb,cost_fix_2_dw,cost_fix_3_wy,cost_fix_4_hc,cost_fix_5_xl,cost_nenghao,cost_tower_elec,cost_tower_zu,cost_zulin,cost_liao,cost_client,cost_freq,cost_waibao,cost_other),'~')::numeric prov_value
  31. from sqmdb_cost.chengben_jt_month where stype='网格' and smonth='202206') m_lm --上月
  32. on m_cm.kpi_code=m_lm.kpi_code and m_cm.city_name=m_lm.city_name and m_cm.grid_name=m_lm.grid_name
  33. join
  34. (select smonth,prov_name,city_name,grid_name,
  35. regexp_split_to_table(concat_ws('~','网运成本合计 ','1.修理费 ','(1)维保 ','(2)代维 ','(3)网优 ','(4)耗材 ','(5)修理 ','2.能耗成本 ','3.铁塔电费 ','4.铁塔租费 ','5.租赁费 ','6.客户接入工料 ','7.客户端 ','8.频率占用费 ','9.紧密型外包成本','10.其他 '),'~') kpi_name,
  36. regexp_split_to_table(concat_ws('~','JT_CB_001','JT_CB_002','JT_CB_003','JT_CB_004','JT_CB_005','JT_CB_006','JT_CB_007','JT_CB_008','JT_CB_009','JT_CB_010','JT_CB_011','JT_CB_012','JT_CB_013','JT_CB_014','JT_CB_015','JT_CB_016'),'~') kpi_code,
  37. regexp_split_to_table(concat_ws('~',cost_total,cost_fix_total,cost_fix_1_wb,cost_fix_2_dw,cost_fix_3_wy,cost_fix_4_hc,cost_fix_5_xl,cost_nenghao,cost_tower_elec,cost_tower_zu,cost_zulin,cost_liao,cost_client,cost_freq,cost_waibao,cost_other),'~')::numeric prov_value
  38. from sqmdb_cost.chengben_jt_accum where stype='网格' and smonth='202207') y_cm --本年累计
  39. on m_cm.kpi_code=y_cm.kpi_code and m_cm.city_name=y_cm.city_name and m_cm.grid_name=y_cm.grid_name
  40. join
  41. (select smonth,prov_name,city_name,grid_name,
  42. regexp_split_to_table(concat_ws('~','网运成本合计 ','1.修理费 ','(1)维保 ','(2)代维 ','(3)网优 ','(4)耗材 ','(5)修理 ','2.能耗成本 ','3.铁塔电费 ','4.铁塔租费 ','5.租赁费 ','6.客户接入工料 ','7.客户端 ','8.频率占用费 ','9.紧密型外包成本','10.其他 '),'~') kpi_name,
  43. regexp_split_to_table(concat_ws('~','JT_CB_001','JT_CB_002','JT_CB_003','JT_CB_004','JT_CB_005','JT_CB_006','JT_CB_007','JT_CB_008','JT_CB_009','JT_CB_010','JT_CB_011','JT_CB_012','JT_CB_013','JT_CB_014','JT_CB_015','JT_CB_016'),'~') kpi_code,
  44. regexp_split_to_table(concat_ws('~',cost_total,cost_fix_total,cost_fix_1_wb,cost_fix_2_dw,cost_fix_3_wy,cost_fix_4_hc,cost_fix_5_xl,cost_nenghao,cost_tower_elec,cost_tower_zu,cost_zulin,cost_liao,cost_client,cost_freq,cost_waibao,cost_other),'~')::numeric prov_value
  45. from sqmdb_cost.chengben_jt_accum where stype='网格' and smonth='202107') y_lm --上年同期
  46. on m_cm.kpi_code=y_lm.kpi_code and m_cm.city_name=y_lm.city_name and m_cm.grid_name=y_lm.grid_name
  47. left join sqmdb_cost.dict_city dc on m_cm.city_name=dc.city_name
  48. left join sqmdb_cost.dict_grid_code dgc on city_name_short(m_cm.city_name)=dgc.city_name and m_cm.grid_name=dgc.grid_name
  49. where m_cm.grid_name!='合计'