成本占比.sql 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. --超高租费占比
  2. select a.* from
  3. (select
  4. city_sname as "地市",
  5. sum(case when (coalesce(tower_cost,0)+coalesce(cost_hetong,0))/tower_cost_grid >1.3 then 1 else 0 end) as "超高租费局站",
  6. count(*) as "局站总数",
  7. round(sum(case when (coalesce(tower_cost,0)+coalesce(cost_hetong,0))/tower_cost_grid >1.3 then 1 else 0 end)/count(*)::numeric,4) as "超高租费占比"
  8. from sqmdb_cost.rpt_baobiao_4_cgzf rbc
  9. where tower_cost_grid is not null
  10. and smonth='202206'
  11. group by city_sname) a
  12. left join sqmdb_cost.dict_city dc on a."地市"=dc.city_name
  13. order by dc.sort_id
  14. --方案1:铁塔>2倍+三方>1.5倍
  15. select a.* from
  16. (select
  17. city_sname as "地市",
  18. over_tower_num as "铁塔租费大于本地市铁塔单站租赁费2倍",
  19. over_hetong_num as "合同租金大于本地市铁塔单站租赁费1.5倍",
  20. (over_tower_num+over_hetong_num) as "超高租费局站数量",
  21. total_num as "局站总数",
  22. round((over_tower_num+over_hetong_num)/total_num::numeric,4) as "超高局站占比"
  23. from(
  24. select
  25. city_sname,
  26. sum(case when coalesce(tower_cost,0)/tower_cost_city >2 then 1 else 0 end) as over_tower_num,--铁塔租费大于本地市铁塔单站租赁费2倍
  27. sum(case when coalesce(cost_hetong,0)/tower_cost_city >1.5 then 1 else 0 end) as over_hetong_num,--合同租金大于本地市铁塔单站租赁费1.5倍
  28. count(*) as total_num
  29. from sqmdb_cost.rpt_baobiao_4_cgzf rbc
  30. where tower_cost_grid is not null
  31. and smonth='202206'
  32. group by city_sname) t1 ) a
  33. left join sqmdb_cost.dict_city dc on a."地市"=dc.city_name
  34. order by dc.sort_id
  35. --方案2:铁塔>2.5倍+三方>1.5倍
  36. select a.* from
  37. (select
  38. city_sname as "地市",
  39. over_tower_num as "铁塔租费大于本地市铁塔单站租赁费1.5倍",
  40. over_hetong_num as "合同租金大于本地市铁塔单站租赁费1.5倍",
  41. (over_tower_num+over_hetong_num) as "超高租费局站数量",
  42. total_num as "局站总数",
  43. round((over_tower_num+over_hetong_num)/total_num::numeric,4) as "超高局站占比"
  44. from(
  45. select
  46. city_sname,
  47. sum(case when coalesce(tower_cost,0)/tower_cost_city >1.5 then 1 else 0 end) as over_tower_num,--铁塔租费大于本地市铁塔单站租赁费2倍
  48. sum(case when coalesce(cost_hetong,0)/tower_cost_city >1.5 then 1 else 0 end) as over_hetong_num,--合同租金大于本地市铁塔单站租赁费1.5倍
  49. count(*) as total_num
  50. from sqmdb_cost.rpt_baobiao_4_cgzf rbc
  51. where tower_cost_grid is not null
  52. and smonth='202206'
  53. group by city_sname) t1 ) a
  54. left join sqmdb_cost.dict_city dc on a."地市"=dc.city_name
  55. order by dc.sort_id
  56. --铁塔按一塔一表,合同按报表
  57. select
  58. t1.city_name,
  59. t1.tw_over_num,
  60. t2.ht_over_num,
  61. t1.tw_total_num,
  62. t2.ht_total_num,
  63. (t1.tw_over_num+t2.ht_over_num) as total_over_num,
  64. (t1.tw_total_num+t2.ht_total_num) as total_num,
  65. (t1.tw_over_num+t2.ht_over_num)/(t1.tw_total_num+t2.ht_total_num)::numeric as over_rate
  66. from
  67. --一塔一表
  68. (select
  69. city_name,
  70. sum(case when cost_rate >2 then 1 else 0 end) as tw_over_num,
  71. count(*) as tw_total_num
  72. from (
  73. select
  74. tw.*,
  75. tw_city.tower_cost_avg,
  76. tw.total_cost/tw_city.tower_cost_avg as cost_rate
  77. from
  78. (select city_name_short(city_operator) as city_name,site_addr_id,sum(total_cost) as total_cost
  79. from sqmdb_cost.tower3 t
  80. where sdate='202206' group by city_operator,site_addr_id) tw
  81. left join (select city_name,tower_cost_avg from sqmdb_cost.rpt_tower_cost_city where smonth='202206') tw_city
  82. on tw.city_name=tw_city.city_name)a
  83. group by city_name) t1
  84. left join
  85. --合同金额按局站汇总
  86. (select
  87. city_sname,
  88. sum(case when cost_rate_ht >1.5 then 1 else 0 end) as ht_over_num,
  89. count(*) as ht_total_num
  90. from (
  91. select
  92. ht.*,
  93. tw_city.tower_cost_avg,
  94. ht.cost_hetong/tw_city.tower_cost_avg as cost_rate_ht
  95. from
  96. (select city_sname,station_sid,sum(cost_hetong) as cost_hetong
  97. from sqmdb_cost.rpt_baobiao_4_cgzf rbc
  98. where smonth='202206' and hetong_sid is not null
  99. group by city_sname,station_sid ) ht
  100. left join (select city_name,tower_cost_avg from sqmdb_cost.rpt_tower_cost_city where smonth='202206') tw_city
  101. on ht.city_sname=tw_city.city_name)a
  102. group by city_sname)t2
  103. on t1.city_name=t2.city_sname
  104. left join sqmdb_cost.dict_city dc on t1.city_name=dc.city_name
  105. order by dc.sort_id
  106. --铁塔租金按局站汇总
  107. select
  108. city_sname,
  109. sum(case when cost_rate_tw >2.5 then 1 else 0 end) as tw_over_num,
  110. count(*) as tw_total_num
  111. from (
  112. select
  113. tw.*,
  114. tw_city.tower_cost_avg,
  115. tw.tower_cost/tw_city.tower_cost_avg as cost_rate_tw
  116. from
  117. (select city_sname,station_sid,sum(tower_cost) as tower_cost
  118. from sqmdb_cost.rpt_baobiao_4_cgzf rbc
  119. where smonth='202206' and site_addr_id is not null
  120. group by city_sname,station_sid ) tw
  121. left join (select city_name,tower_cost_avg from sqmdb_cost.rpt_tower_cost_city where smonth='202206') tw_city
  122. on tw.city_sname=tw_city.city_name)a
  123. group by city_sname
  124. --超高电费占比
  125. select a.* from
  126. (select
  127. city_sname as "地市",
  128. sum(case when over_lilun_power >3.5 then 1 else 0 end) as "超高电费局站",
  129. count(*) as "局站总数",
  130. round(sum(case when over_lilun_power >3.5 then 1 else 0 end)/count(*)::numeric,4) as "超高电费占比"
  131. from sqmdb_cost.rpt_baobiao_6_cgnh rbc
  132. where city_sname is not null and station_type is not null and lilun_power>=100
  133. and station_type not in ('光跳接入局站','核心局站','汇聚局站','综合业务接入点')
  134. and smonth='202206'
  135. group by city_sname) a
  136. left join sqmdb_cost.dict_city dc on a."地市"=dc.city_name
  137. order by dc.sort_id