chengben_quzhun_1_c_grid.sql 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. ---1-c.大于2倍铁塔单站租赁费三方站点占比
  2. ---chengben_quzhun_1_c_grid_202203.csv
  3. ----网格
  4. select
  5. t1.*,
  6. t2.city_code*100 as city_code,
  7. t3.area_code
  8. from
  9. (select sdate,city_name,area_name,
  10. sum(case when property_type='租用第三方' then 1 else 0 end) as cost_over2b_3rd_num,
  11. count(*) as station_num,
  12. sum(case when property_type='租用第三方' then 1 else 0 end)/count(*)::numeric as over_rate_3rd
  13. from(
  14. select *,
  15. cost_site.cost_tower/cost_cbzx.cbzx_cost_avg as cost_rate
  16. from
  17. (select station_sid,city_name,area_name,property_type,tower_code from sqmdb_cost.station3 s where s.property_type in ('租用铁塔','租用第三方')) st
  18. join
  19. (select sdate,site_addr_id,sum(total_cost) as cost_tower from sqmdb_cost.tower3 t group by sdate,site_addr_id) cost_site
  20. on st.tower_code=cost_site.site_addr_id
  21. join sqmdb_cost.dict_tower_cbzx dtc on st.tower_code=dtc.tower_code
  22. join
  23. (select sdate as cbzx_sdate,cbzx,cbzx_cost_avg from sqmdb_cost.v_tower_cost_cbzx) cost_cbzx
  24. on cost_site.sdate=cost_cbzx.cbzx_sdate::varchar and dtc.cbzx=cost_cbzx.cbzx
  25. where cost_site.cost_tower/cost_cbzx.cbzx_cost_avg>2
  26. and cost_site.sdate='202204') a
  27. group by sdate,city_name,area_name) t1
  28. left join
  29. (select distinct city_code,city_name from sqmdb_cost.dict_grid) t2
  30. on t1.city_name=t2.city_name
  31. left join
  32. (select distinct city_code,city_name,area_code,area_name from sqmdb_cost.dict_grid) t3
  33. on t1.city_name=t3.city_name and t1.area_name=t3.area_name
  34. order by t2.city_code,t3.area_code