gap_analysis.txt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. -- 停车缺口分析
  2. select
  3. t2.area_name,
  4. ifnull(round(count(case when t2.occupancy_rate>70 then park_id end)/count(t2.park_id),2),0)*100 as
  5. parking_gap_rate
  6. from
  7. (select
  8. area_name,
  9. park_id,
  10. ifnull(round(occupancy_parking_number*100/total_parking_number,2),0) as occupancy_rate
  11. from
  12. (SELECT
  13. area_id,
  14. area_name,
  15. t.park_id,
  16. CASE
  17. WHEN
  18. sum( remain_parking_number ) IS NULL THEN
  19. 0 ELSE sum( remain_parking_number )
  20. END remain_parking_number,-- 空闲位
  21. CASE
  22. WHEN sum( total_parking_number ) - sum( remain_parking_number ) IS NULL THEN
  23. 0 ELSE sum( total_parking_number ) - sum( remain_parking_number )
  24. END occupancy_parking_number, -- 占用位
  25. CASE
  26. WHEN sum( total_parking_number ) IS NULL THEN
  27. 0 ELSE sum( total_parking_number ) END as total_parking_number
  28. FROM
  29. luo_park_baseinfo t
  30. LEFT JOIN luo_parking_berths a ON t.park_id = a.park_id
  31. AND a.CREATE_TIME >= ( SELECT max( CREATE_TIME ) max_time FROM luo_parking_berths )
  32. group by 1,2,3) t1) t2
  33. group by 1
  34. -- 停车缺口变化趋势
  35. select
  36. t2.HOUR_flag,
  37. ifnull(round(count(case when t2.occupancy_rate>99 then park_id end)/count(t2.park_id),2),0)*100 as
  38. parking_gap_rate
  39. from
  40. (select
  41. ifnull(HOUR_flag,0) HOUR_flag,
  42. park_id,
  43. ifnull(round(order_num*100/total_parking_number,2),0) as occupancy_rate
  44. from
  45. (SELECT
  46. t.park_id,
  47. a.total_parking_number,
  48. c.order_num,
  49. c.HOUR_flag
  50. FROM
  51. luo_park_baseinfo t
  52. LEFT JOIN luo_parking_berths a ON t.park_id = a.park_id
  53. AND a.CREATE_TIME >= ( SELECT max( CREATE_TIME ) max_time FROM luo_parking_berths )
  54. left join (select park_id,HOUR(in_time) as HOUR_flag, count(b.order_no) as order_num
  55. from luo_parking_inrecord b
  56. where HOUR(in_time) is not null
  57. group by 1,2) c
  58. on t.park_id = c.park_id) t1) t2
  59. group by 1