22_grid.sql 1.0 KB

123456789101112131415161718192021222324252627282930
  1. --22、超高电价占比
  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. '22' as ZB_CODE,
  12. '超高电价占比' as ZB_NAME,
  13. '是' as IS_RATIO,
  14. a.high_price_num as QZ_FZ,
  15. a.total_num as QZ_FM,
  16. a.high_price_rate as BY_QZ
  17. from
  18. (select smonth,grid_code,
  19. count(*) as total_num,
  20. sum(case when y.eprice>0.8 then 1 else 0 end) as high_price_num,
  21. sum(case when y.eprice>0.8 then 1 else 0 end)/count(*)::numeric as high_price_rate
  22. from
  23. (select yn.smonth,dgc.grid_code,(case when accrued_power=0 then 0 else accrued_cost/accrued_power end) as eprice
  24. from sqmdb_cost.ytmx_new yn
  25. join sqmdb_cost.dict_grid_code dgc
  26. on city_name_short(yn.city_name)=dgc.city_name and trim(yn.area_name)=trim(dgc.grid_name)
  27. where yn.build_type_name not in ('办公楼','办公用房','营业用房') and yn.smonth='202207') y
  28. group by smonth,grid_code) a
  29. join sqmdb_cost.dict_code_grid dcg on a.grid_code=dcg.grid_code
  30. order by dcg.city_code