一些语句.sql 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. -- 重复工单
  2. with t1 as (select compl_area_local,busi_no from report_auto.he_d_mobile_comp hdmc where month_id = substring('20230420' from 1 for 6) and day_id <= substring('20230420' from 7 for 2)),
  3. t2 as (select distinct * from t1),
  4. t3 as (select compl_area_local, count(1) as total_num from t1 group by compl_area_local),
  5. t4 as (select compl_area_local, count(1) as distinct_num from t2 group by compl_area_local),
  6. t5 as (select t3.compl_area_local, t3.total_num, t3.total_num - t4.distinct_num as repeat_num, (t3.total_num - t4.distinct_num)/t3.total_num::numeric as repeat_ratio from T3, t4 where t3.compl_area_local = t4.compl_area_local)
  7. select '全省' as compl_area_local, sum(total_num) as total_num, sum(repeat_num) as repeat_num, sum(repeat_num) /sum(total_num)::numeric as repeat_ratio from t5
  8. union select * from t5
  9. -- 超时工单
  10. with t1 as (select compl_area_local, is_timeout from report_auto.he_d_mobile_comp hdmc where month_id = substring('20230420' from 1 for 6) and day_id <= substring('20230420' from 7 for 2)),
  11. t2 as (select '全省' as compl_area_local, count(1) as total_num from t1),
  12. t3 as (select compl_area_local, count(1) as total_num from t1 group by compl_area_local),
  13. t4 as (select * from t2 union select * from t3),
  14. t5 as (select compl_area_local from t1 where is_timeout = '是'),
  15. t7 as (select '全省' as compl_area_local, count(1) as timeout_num from t5),
  16. t8 as (select compl_area_local, count(1) as timeout_num from t5 group by compl_area_local),
  17. t9 as (select * from t7 union select * from t8)
  18. select t4.compl_area_local, t4.total_num, t9.timeout_num, t9.timeout_num/t4.total_num::numeric as timeout_ratio from t4,t9 where t4.compl_area_local = t9.compl_area_local order by t9.timeout_num/t4.total_num::numeric desc
  19. -- 超时时间
  20. with t1 as (select compl_area_local, case when proce_time != '' then (extract('epoch' from to_timestamp(proce_time, 'YYYY-MM-DD HH24:MI:SS')) - extract('epoch' from to_timestamp(accept_time, 'YYYY-MM-DD HH24:MI:SS')))/3600 when is_online_complete = '是' then 0
  21. else (extract('epoch' from to_timestamp(end_time, 'YYYY-MM-DD HH24:MI:SS')) - extract('epoch' from to_timestamp(accept_time, 'YYYY-MM-DD HH24:MI:SS')))/3600 end as duration
  22. from report_auto.he_d_mobile_comp hdmc where month_id = substring('20230420' from 1 for 6) and day_id <= substring('20230420' from 7 for 2))
  23. select compl_area_local, avg(duration) as avg_duration from t1 group by compl_area_local
  24. -- 客户端统计
  25. with t1 as (select businoareaname, complaint_satisfied_list::numeric, complaint_satisfied_count::numeric,
  26. complaint_resolution_list::numeric, complaint_resolution_count::numeric,
  27. complaint_response_list::numeric, complaint_response_count::numeric from report_auto.he_d_high_quality hdhq
  28. where acct_date = '2023-04-20'
  29. and profes_dep = '网络质量'
  30. and big_type_name = '移网网络体验'
  31. and small_type_name = '--')
  32. select '全省' as businoareaname,
  33. sum(complaint_satisfied_list) / sum(complaint_satisfied_count) as complaint_satisfied,
  34. sum(complaint_resolution_list) / sum(complaint_resolution_count) as complaint_resolution,
  35. sum(complaint_response_list) / sum(complaint_response_count) as complaint_response from t1 union
  36. select businoareaname,
  37. complaint_satisfied_list / complaint_satisfied_count as complaint_satisfied,
  38. complaint_resolution_list / complaint_resolution_count as complaint_resolution,
  39. complaint_response_list / complaint_response_count as complaint_response from t1
  40. select month_id, day_id, count(1)
  41. from tsl_data.high_quality_list_day
  42. group by month_id, day_id
  43. order by month_id, day_id;
  44. select month_id, day_id, count(1)
  45. from tsl_data.mobile_complaint_day
  46. group by month_id, day_id
  47. order by month_id, day_id;
  48. select day_id, count(1)
  49. from tsl_data.high_quality_data
  50. group by day_id
  51. order by day_id;
  52. select month_id, city_name, management_target_ts_ratio, target_ts_ratio
  53. from report_auto.target_ts_ratio
  54. where month_id = '202312'
  55. order by city_name;
  56. update report_auto.target_ts_ratio
  57. set management_target_ts_ratio = 4.10, target_ts_ratio =4.1
  58. where month_id = '202312'
  59. and city_name in ('保定', '秦皇岛', '唐山');
  60. update report_auto.target_ts_ratio
  61. set management_target_ts_ratio = 3.90, target_ts_ratio =3.9
  62. where month_id = '202312'
  63. and city_name in ('沧州', '承德', '邯郸', '邢台');
  64. update report_auto.target_ts_ratio
  65. set management_target_ts_ratio = 3.40, target_ts_ratio =3.4
  66. where month_id = '202312'
  67. and city_name = '衡水';
  68. update report_auto.target_ts_ratio
  69. set management_target_ts_ratio = 4.20, target_ts_ratio =4.2
  70. where month_id = '202312'
  71. and city_name = '廊坊';
  72. update report_auto.target_ts_ratio
  73. set management_target_ts_ratio = 4.00, target_ts_ratio =4.0
  74. where month_id = '202312'
  75. and city_name in ('石家庄', '张家口', '全省');
  76. update report_auto.target_ts_ratio
  77. set management_target_ts_ratio = 4.90, target_ts_ratio =4.9
  78. where month_id = '202312'
  79. and city_name = '雄安';