24.sql 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --24、租赁局站占比
  2. ------------------------使用station3------------------------
  3. ---地市
  4. select
  5. city_name,
  6. count(*) as total_num,
  7. sum(case when property_type like '%租用%' then 1 else 0 end) as zu_num,
  8. sum(case when property_type like '%租用%' then 1 else 0 end)/count(*)::numeric as zu_rate
  9. from sqmdb_cost.station3
  10. group by city_name
  11. order by city_name
  12. ---网格
  13. select
  14. city_name,area_name,
  15. count(*) as total_num,
  16. sum(case when property_type like '%租用%' then 1 else 0 end) as zu_num,
  17. sum(case when property_type like '%租用%' then 1 else 0 end)/count(*)::numeric as zu_rate
  18. from sqmdb_cost.station3
  19. group by city_name,area_name
  20. order by city_name,area_name
  21. ------------------------使用station2------------------------
  22. --select * from sqmdb_cost.dict where dicttext like '%租用%'(99928:租用铁塔,99931:租用第三方)
  23. ---地市
  24. select
  25. c.dicttext as city_name,
  26. a.zuyong::numeric/b.total::numeric as zu_rate
  27. from
  28. (select city_code,count(*) as zuyong from sqmdb_cost.station2 where property_type in ('99928','99931') group by city_code) a
  29. left join
  30. (select city_code,count(*) as total from sqmdb_cost.station2 group by city_code) b
  31. on a.city_code=b.city_code
  32. left join sqmdb_cost.dict c on a.city_code::varchar=c.dictid
  33. order by c.dicttext
  34. ---网格
  35. select
  36. c.dicttext as city_name,
  37. d.dicttext as area_name,
  38. a.zuyong::numeric/b.total::numeric as zu_rate
  39. from
  40. (select city_code,area_code,count(*) as zuyong from sqmdb_cost.station2 where property_type in ('99928','99931') group by city_code,area_code) a
  41. left join
  42. (select city_code,area_code,count(*) as total from sqmdb_cost.station2 group by city_code,area_code) b
  43. on a.city_code=b.city_code and a.area_code=b.area_code
  44. left join sqmdb_cost.dict c on a.city_code::varchar=c.dictid
  45. left join sqmdb_cost.dict d on a.area_code::varchar=d.dictid
  46. order by c.dicttext,d.dicttext