22.sql 776 B

12345678910111213141516171819202122232425
  1. --22、超高电价占比
  2. ---地市(可由网格数据汇聚)
  3. select
  4. smonth,
  5. city_name,
  6. count(*) as total_num,
  7. sum(case when y.eprice>0.8 then 1 else 0 end) as high_price_num,
  8. sum(case when y.eprice>0.8 then 1 else 0 end)/count(*)::numeric as high_price_rate
  9. from
  10. (select *,(case when accrued_power=0 then 0 else accrued_cost/accrued_power end) as eprice from sqmdb_cost.ytmx_new) y
  11. group by smonth,city_name
  12. ---网格
  13. select
  14. smonth,
  15. city_name,
  16. area_name,
  17. count(*) as total_num,
  18. sum(case when y.eprice>0.8 then 1 else 0 end) as high_price_num,
  19. sum(case when y.eprice>0.8 then 1 else 0 end)/count(*)::numeric as high_price_rate
  20. from
  21. (select *,(case when accrued_power=0 then 0 else accrued_cost/accrued_power end) as eprice from sqmdb_cost.ytmx_new) y
  22. group by smonth,city_name,area_name