21_grid.sql 944 B

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