berth_road.txt 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. --停车饱和度
  2. select week_day,
  3. sum(occupancy_parking_number) as occupancy_parking_number,-- 占用
  4. sum(remain_parking_number) as remain_parking_number-- 空闲
  5. from (SELECT
  6. park_id,
  7. WEEKDAY(CREATE_TIME)+1 as week_day,
  8. max(total_parking_number) total_parking_number,
  9. min(remain_parking_number) remain_parking_number,
  10. max(total_parking_number)-min(remain_parking_number) as occupancy_parking_number
  11. FROM
  12. luo_parking_berths
  13. where remain_parking_number>=0
  14. group by 1,2) a
  15. group by 1
  16. -- 停车场周转率分析
  17. select week_day,
  18. round(sum(parking_num)*100/sum(total_parking_number),2) as parking_turnover_rate
  19. from
  20. (SELECT
  21. WEEKDAY(t.in_time)+1 as week_day,
  22. t.park_id,
  23. b.total_parking_number,
  24. count( t.parking_no ) AS parking_num,
  25. count( t.parking_no )/b.total_parking_number
  26. FROM
  27. luo_parking_inrecord t
  28. inner join luo_parking_berths b on t.park_id = b.park_id and b.CREATE_TIME = (
  29. SELECT
  30. max( CREATE_TIME ) max_time
  31. FROM
  32. luo_parking_berths
  33. WHERE
  34. create_time >= curdate())
  35. GROUP BY 1,2,3) t1
  36. GROUP BY 1
  37. -- 特殊车辆进场占比 改为 车辆类型进场占比
  38. select
  39. car_type,
  40. count(order_no) as parking_num
  41. from
  42. luo_parking_inrecord
  43. group by 1
  44. -- 停车场营收分析
  45. select
  46. case when WEEKDAY(c.pay_time)+1 is null then 1 else WEEKDAY(c.pay_time)+1 end pay_time,
  47. case when sum(amount) is null then 0 else round(sum(amount)/100,2) end as amount
  48. FROM
  49. luo_park_baseinfo t
  50. left join
  51. (select a.park_id,a.pay_time,b.amount
  52. from luo_parking_chargerecord a
  53. inner join luo_parking_chargerecord_subject b
  54. on a.order_no=b.order_no) c
  55. ON t.park_id = c.park_id
  56. group by 1
  57. -- 车辆进出场趋势
  58. select
  59. b.week_day,
  60. round(park_in_num*100/(park_in_num+park_out_num),2) as inflow_rate,
  61. round(park_out_num*100/(park_in_num+park_out_num),2) as outflow_rate
  62. from
  63. (select
  64. WEEKDAY(in_time)+1 as week_day,
  65. case when count(parking_no) is null then 0 else count(parking_no) end as park_in_num
  66. from
  67. luo_park_baseinfo t
  68. LEFT JOIN luo_parking_inrecord a
  69. ON t.park_id = a.park_id
  70. where WEEKDAY(in_time) is not null
  71. group by 1) b
  72. left join
  73. (select
  74. WEEKDAY(out_time)+1 as week_day,
  75. case when count(parking_no) is null then 0 else count(parking_no) end as park_out_num
  76. from
  77. luo_park_baseinfo t
  78. LEFT JOIN luo_parking_outrecord a
  79. ON t.park_id = a.park_id
  80. where WEEKDAY(out_time) is not null
  81. group by 1) c
  82. on b.week_day=c.week_day