zwjs_cb_hb_city.sql 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. --省内口径(地市)
  2. select
  3. m_cm.smonth as "date",
  4. '河北' as province_name,
  5. m_cm.city_name,
  6. dc.city_code as city_code,
  7. m_cm.kpi_name as index_name,
  8. m_cm.kpi_code as index_id,
  9. '万元' as index_unit,
  10. m_cm.city_value as this_month,
  11. m_lm.city_value as last_month,
  12. (m_cm.city_value::numeric-m_lm.city_value::numeric) as month_on_month,
  13. case when m_lm.city_value::numeric=0 then 0 else (m_cm.city_value::numeric-m_lm.city_value::numeric)/m_lm.city_value::numeric end as month_on_month_grow,
  14. y_cm.city_value as this_year,
  15. y_lm.city_value as last_year,
  16. (y_cm.city_value::numeric-y_lm.city_value::numeric) as year_on_year,
  17. case when y_lm.city_value::numeric=0 then 0 else (y_cm.city_value::numeric-y_lm.city_value::numeric)/y_lm.city_value::numeric end as year_on_year_grow
  18. from
  19. (select smonth,kpi_code,kpi_name,
  20. regexp_split_to_table(concat_ws('~','石家庄','唐山','秦皇岛','邯郸','邢台','保定','张家口','承德','廊坊','沧州','衡水','雄安','本部'),'~') city_name,
  21. regexp_split_to_table(concat_ws('~',heb_city1,heb_city2,heb_city3,heb_city4,heb_city5,heb_city6,heb_city7,heb_city8,heb_city9,heb_city10,heb_city11,heb_city12,heb_city13),'~') city_value
  22. from sqmdb_cost.chengben_heb_month where smonth='202207') m_cm --本月
  23. join
  24. (select smonth,kpi_code,kpi_name,
  25. regexp_split_to_table(concat_ws('~','石家庄','唐山','秦皇岛','邯郸','邢台','保定','张家口','承德','廊坊','沧州','衡水','雄安','本部'),'~') city_name,
  26. regexp_split_to_table(concat_ws('~',heb_city1,heb_city2,heb_city3,heb_city4,heb_city5,heb_city6,heb_city7,heb_city8,heb_city9,heb_city10,heb_city11,heb_city12,heb_city13),'~') city_value
  27. from sqmdb_cost.chengben_heb_month where smonth='202206') m_lm --上月
  28. on m_cm.kpi_code=m_lm.kpi_code and m_cm.city_name=m_lm.city_name
  29. join
  30. (select smonth,kpi_code,kpi_name,
  31. regexp_split_to_table(concat_ws('~','石家庄','唐山','秦皇岛','邯郸','邢台','保定','张家口','承德','廊坊','沧州','衡水','雄安','本部'),'~') city_name,
  32. regexp_split_to_table(concat_ws('~',heb_city1,heb_city2,heb_city3,heb_city4,heb_city5,heb_city6,heb_city7,heb_city8,heb_city9,heb_city10,heb_city11,heb_city12,heb_city13),'~') city_value
  33. from sqmdb_cost.chengben_heb_accum where smonth='202207') y_cm --本年累计
  34. on m_cm.kpi_code=y_cm.kpi_code and m_cm.city_name=y_cm.city_name
  35. join
  36. (select smonth,kpi_code,kpi_name,
  37. regexp_split_to_table(concat_ws('~','石家庄','唐山','秦皇岛','邯郸','邢台','保定','张家口','承德','廊坊','沧州','衡水','雄安','本部'),'~') city_name,
  38. regexp_split_to_table(concat_ws('~',heb_city1,heb_city2,heb_city3,heb_city4,heb_city5,heb_city6,heb_city7,heb_city8,heb_city9,heb_city10,heb_city11,heb_city12,heb_city13),'~') city_value
  39. from sqmdb_cost.chengben_heb_accum where smonth='202107') y_lm --上年同期
  40. on m_cm.kpi_code=y_lm.kpi_code and m_cm.city_name=y_lm.city_name
  41. left join sqmdb_cost.dict_city dc on m_cm.city_name=dc.city_name