23_grid.sql 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. --23、铁塔共享率 select * from sqmdb_cost.tower3
  2. ---网格
  3. select
  4. t1.sdate 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. '23' as ZB_CODE,
  12. '铁塔共享率' as ZB_NAME,
  13. '是' as IS_RATIO,
  14. t1.share_num as QZ_FZ,
  15. t1.total_num as QZ_FM,
  16. t1.share_rate as BY_QZ
  17. from
  18. (select sdate,city_name,grid_code,
  19. sum(case when is_duxiang='共享' then 1 else 0 end) as share_num,
  20. count(*) as total_num,
  21. sum(case when is_duxiang='共享' then 1 else 0 end)/count(*)::numeric as share_rate
  22. from
  23. (select t.*,dgc.grid_code from
  24. (select distinct sdate,city_name_short(city_operator) as city_name,area_operator,site_addr_id,is_duxiang
  25. from sqmdb_cost.tower3
  26. where stype in ('新建及共享改造','存量注入') and sdate='202206') t
  27. join sqmdb_cost.dict_grid_code dgc on t.city_name=dgc.city_name and trim(t.area_operator)=dgc.grid_name
  28. where dgc.grid_code is not null) a
  29. group by sdate,city_name,grid_code) t1
  30. join sqmdb_cost.dict_code_grid dcg on t1.grid_code=dcg.grid_code
  31. order by dcg.city_code