21_city.sql 824 B

12345678910111213141516171819202122232425262728
  1. --21、转供电占比
  2. ---地市(可由网格数据汇聚)
  3. select
  4. a.smonth as MONTH_ID,
  5. '地市' as ZB_TYPE,
  6. '河北' as PROV_NAME,
  7. dg.city_code*100 as CITY_ID,
  8. a.city_name as CITY_NAME,
  9. null as GRID_ID,
  10. null as GRID_NAME,
  11. '21' as ZB_CODE,
  12. '转供电占比' as ZB_NAME,
  13. '是' as IS_RATIO,
  14. zgd_num as QZ_FZ,
  15. total_num as QZ_FM,
  16. zgd_rate as BY_QZ
  17. from
  18. (select smonth,city_name,
  19. count(*) as total_num,
  20. sum(case when y.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end) as zgd_num,
  21. sum(case when y.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end)/count(*)::numeric as zgd_rate
  22. from sqmdb_cost.ytmx_new y
  23. where build_type_name not in ('办公楼','办公用房','营业用房') and smonth='202206'
  24. group by smonth,city_name) a
  25. join
  26. (select distinct city_code,city_name from sqmdb_cost.dict_grid) dg
  27. on a.city_name=dg.city_name
  28. order by dg.city_code