指标.sql 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. --删除分区
  2. --先解除父表与分区表绑定关系
  3. alter table sqmdb_bak.sdrflow detach partition sqmdb_bak.sdrflow_20220429;
  4. --再删除分区表
  5. drop table sqmdb_bak.sdrflow_20220429
  6. select pg_relation_filepath('sqmdb_bak.sdrflow_20220429');
  7. --查看数据库大小
  8. --select pg_database.datname, pg_size_pretty (pg_database_size(pg_database.datname)) AS size from pg_database;
  9. select relname, pg_size_pretty(pg_relation_size(relid)) from pg_stat_user_tables where schemaname='o2p' order by pg_relation_size(relid) desc
  10. select relname, pg_size_pretty(pg_relation_size(relid)) from pg_stat_user_tables where schemaname='sqmdb_bak' and relname like '%sdr%' order by pg_relation_size(relid) desc
  11. --select pg_database_size('sqmmt')/1024/1024/1024 as gb;
  12. select sdate,count(*) from o2p.sdr_0_4g_flow_cell_day group by sdate
  13. SELECT
  14. table_schema || '.' || table_name AS table_full_name,
  15. pg_size_pretty(pg_total_relation_size('"' || table_schema || '"."' || table_name || '"')) AS size
  16. FROM information_schema.tables
  17. ORDER BY
  18. pg_total_relation_size('"' || table_schema || '"."' || table_name || '"') DESC ;
  19. select pg_database.datname, pg_database_size(pg_database.datname)/1024/1024/1024/1024::numeric AS size_tb from pg_database;
  20. select (regexp_split_to_array('127.134555.17','\.'))[2]::numeric
  21. select case
  22. when to_number((regexp_split_to_array('127.134555.17','\.'))[2],'000000') between 134554 and 134559 then '1' else '0' end
  23. --北10:'北京','天津','河北','山西','内蒙古','辽宁','吉林','黑龙江','山东','河南'
  24. select date_trunc('day',sdate) from sqmdb_cost.kuandai_ftth kf
  25. --到期合同
  26. select * from hetong2 where date_part('day',edate::timestamp-now()::timestamp) <= 0;
  27. select *,
  28. extract(year from age(edate+'1 day',bdate))*12+
  29. extract(month from age(edate+'1 day',bdate))+
  30. extract(day from age(edate+'1 day',bdate))/30 as nmonth
  31. from sqmdb_cost.hetong
  32. select datname,pg_encoding_to_char(encoding) as encoding from pg_database;
  33. with amount_type as (
  34. select distinct report_id,smonth,period,period_type,
  35. segment1,segment1_name,prov_code,prov_name,city_code,
  36. city_name,grid_code,grid_name,a.sort_id,column_tag,amount,
  37. b.type1,b.type2,b.type3,b.leixing1,b.leixing2
  38. from sqmdb_cost.jituanchengben_e a
  39. left join sqmdb_cost.dict_report49 b on b.sort_id=a.sort_id
  40. where a.smonth='202111' and a.report_id='49'
  41. and ds_cn='归集+横向分摊+调差' and prov_name='河北'
  42. )
  43. select report_id,"period",smonth,city_name,leixing2,sum(amount) from amount_type
  44. where leixing2 in ('修理费','铁塔租赁费' ) and "period"='2021-11Y'
  45. group by report_id,"period",smonth,city_name,leixing2
  46. select * from sqmdb_cost.station_hetong where station_sid =14900001104874 --有重复
  47. --月份区间
  48. select date_trunc('month',current_date - interval '1' month)
  49. union
  50. select date_trunc('month',current_date)
  51. select t.*,dtc.cbzx from
  52. (select sdate,city_operator,area_operator,site_addr_id,sum(total_cost) as total_cost from
  53. sqmdb_cost.tower2 where sdate='202203' group by sdate,city_operator,area_operator,site_addr_id) t
  54. left join sqmdb_cost.dict_tower_cbzx dtc on t.site_addr_id=dtc.tower_code
  55. --bbu
  56. select * from
  57. (select * from sqmdb_cost.equip e) a
  58. join
  59. (select * from sqmdb_cost.nenghao_bbu nb) b
  60. on a.eqp_name=b.sitename
  61. select date_trunc('month',to_date('202204','YYYYMM'))
  62. select sdate,count(*) from sqmdb_cost.kuandai_ftth group by sdate order by sdate desc
  63. select date_trunc('month',to_date('202203','yyyymm'))
  64. select date_trunc('month',to_date('202203','yyyymm') + interval '1' month)
  65. select * from sqmdb_cost.rpt_dport_cost_grid rdcg where smonth='202204' and grid_name like '%深泽%'
  66. select to_char((to_date('202203','yyyymm') - interval '1 years'),'yyyy12')
  67. select to_char((now() - interval '1 month'),'yyyymm')
  68. select sdate,count(*) from sqmdb_cost.tower3 t group by sdate order by sdate desc
  69. select sdate,count(*) from sqmdb_cost.kuandai_ftth kf group by sdate order by sdate desc
  70. select max(cbzx_code) as mycode from sqmdb_cost.dict_grid_code where cbzx_code>9013040000
  71. --update sqmdb_cost.dict_grid
  72. --set sort_id=dcg.sort_id
  73. --from sqmdb_cost.dict_code_grid dcg
  74. --where sqmdb_cost.dict_grid.city_code=dcg.city_code
  75. --update sqmdb_cost.rpt_baobiao_3_dzzl
  76. --set sort_id_city=dcg.sort_id
  77. --from sqmdb_cost.dict_code_grid dcg
  78. --where sqmdb_cost.rpt_baobiao_3_dzzl.city_code=dcg.city_code*100
  79. select
  80. dcg.grid_code,
  81. dcg.city_name,
  82. dz.area_id,
  83. dz.area_name,
  84. dz.p_id
  85. from sqmdb_cost.dict_code_grid dcg
  86. join sqmdb_cost.dict_zzjg dz on dcg.area_code=dz.area_id
  87. select distinct cname,dname from sqmdb_cost.hetong_new hn
  88. select date_trunc('month',now())
  89. select * from
  90. (select distinct area_code,grid_id,grid_name from sqmdb_cost.room) a
  91. left join sqmdb_cost.dict_grid_code dgc on trim(a.grid_name)=trim(dgc.grid_name)
  92. where dgc.grid_name is null
  93. select station_sid,station_sname,tower_code from sqmdb_cost.station3 s where station_sid='14900001518654'
  94. --合同--输出报表
  95. select
  96. city_name as 地市名称,
  97. sid as 合同编码,
  98. sname as 合同名称,
  99. cbzx as 合同成本中心,
  100. idx_station_sid as 索引表局站ID,
  101. idx_hetong_sid as 索引表合同编码,
  102. stype as 合同校验
  103. from sqmdb_cost.err_has_ht_no_station err
  104. where not exists (select hetong_sid from sqmdb_cost.hetong_white hw where err.sid=hw.hetong_sid)
  105. order by sort_id_city
  106. select
  107. smonth,grid_code,
  108. count(*) as total_num,
  109. sum(case when stype='有合同有局站' then 1 else 0 end) as has_num,
  110. sum(case when stype!='有合同有局站' then 1 else 0 end) as no_num
  111. from sqmdb_cost.err_has_ht_no_station
  112. group by smonth,grid_code
  113. select dictid,count(*) from sqmdb_cost.dict group by dictid having count(*)>1
  114. select * from sqmdb_cost.dict
  115. --insert into sqmdb_cost.chengben_shengnei_m
  116. select
  117. smonth,
  118. stype,
  119. sname,
  120. income,
  121. cost_total,
  122. cost_fix,
  123. cost_liao
  124. from sqmdb_cost.chengben_shengnei where smonth='202201'
  125. --insert into sqmdb_cost.chengben_shengnei_m
  126. select cm.smonth,cm.stype,cm.sname,
  127. cm.income-lm.income as income,
  128. cm.cost_total-lm.cost_total as cost_total,
  129. cm.cost_fix-lm.cost_fix as cost_fix,
  130. cm.cost_liao-lm.cost_liao as cost_liao
  131. from
  132. (select * from sqmdb_cost.chengben_shengnei where smonth='202202') cm
  133. join
  134. (select * from sqmdb_cost.chengben_shengnei where smonth='202201') lm
  135. on cm.stype=lm.stype and cm.sname=lm.sname
  136. select * from sqmdb_cost.station s where station_sid ='14900001060000'
  137. select avg(nh_kwh) from sqmdb_cost.nenghao_rru nr
  138. where net_type='4G' and changjia='中兴' and smonth='202201'
  139. --truncate table sqmdb_cost.equip
  140. --insert into sqmdb_cost.equip
  141. --select * from sqmdb_cost.equip_e
  142. SELECT
  143. gusuan_3g.cell_id,
  144. room.station_sid,
  145. 61.6681 AS nh_kwh
  146. FROM gusuan_3g,
  147. room,
  148. roomid
  149. WHERE gusuan_3g.room_id = roomid.room_id AND room.room_sid = roomid.room_sid
  150. select smonth,changjia,net_type,count(*) as cell_num from sqmdb_cost.nenghao_rru
  151. where changjia='中兴' group by smonth,changjia,net_type order by smonth desc
  152. select * from sqmdb_cost.station_hetong sh where station_sid ='14900001078418'
  153. select stype,count(*) from
  154. (select * from sqmdb_cost.tower3 t
  155. where sdate='202206' and city_operator='邯郸市' and area_operator like '%成安%') a
  156. group by stype
  157. SELECT distinct station_sid,city_code*100 as city_code,area_code FROM sqmdb_cost.station s
  158. select sdate,count(*) from sqmdb_cost.kuandai_ftth group by sdate order by sdate
  159. select * from sqmdb_cost.kuandai_ftth kf where sdate=to_date('20220809','yyyymmdd')