21.sql 655 B

12345678910111213141516171819202122
  1. --21、转供电占比
  2. ---地市(可由网格数据汇聚)
  3. select
  4. smonth,
  5. city_name,
  6. count(*) as total_num,
  7. sum(case when y.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end) as zgd_num,
  8. sum(case when y.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end)/count(*)::numeric as zgd_rate
  9. from sqmdb_cost.ytmx_new y
  10. group by smonth,city_name
  11. ---网格
  12. select
  13. smonth,
  14. city_name,
  15. area_name,
  16. count(*) as total_num,
  17. sum(case when y.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end) as zgd_num,
  18. sum(case when y.meter_type_name='12-01 | 转供手抄表' then 1 else 0 end)/count(*)::numeric as zgd_rate
  19. from sqmdb_cost.ytmx_new y
  20. group by smonth,city_name,area_name