parking_operate.txt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. sum(parking_num)*100/sum(total_parking_number) 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. case when WEEKDAY(c.pay_time)+1 is null then 1 else WEEKDAY(c.pay_time)+1 end pay_time,
  40. case when sum(amount) is null then 0 else round(sum(amount)/100,2) end as amount
  41. FROM
  42. luo_park_baseinfo t
  43. left join
  44. (select a.park_id,a.pay_time,b.amount
  45. from luo_parking_chargerecord a
  46. inner join luo_parking_chargerecord_subject b
  47. on a.order_no=b.order_no) c
  48. ON t.park_id = c.park_id
  49. group by 1
  50. -- 特殊车辆进场占比 改为 车辆类型进场占比
  51. select
  52. car_type,
  53. count(order_no) as parking_num
  54. from
  55. luo_parking_inrecord
  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
  83. -- 停车场营收对比分析
  84. -- 双汇广场停车场 和 大润发地下停车场
  85. select
  86. park_name,
  87. pay_time,
  88. amount
  89. from
  90. (select
  91. t.park_id,
  92. t.park_name,
  93. case when WEEKDAY(c.pay_time)+1 is null then 1 else WEEKDAY(c.pay_time)+1 end pay_time,
  94. case when sum(amount) is null then 0 else round(sum(amount)/100,2) end as amount
  95. FROM
  96. luo_park_baseinfo t
  97. inner join
  98. (select a.park_id,a.pay_time,b.amount
  99. from luo_parking_chargerecord a
  100. inner join luo_parking_chargerecord_subject b
  101. on a.order_no=b.order_no) c
  102. ON t.park_id = c.park_id
  103. group by 1,2,3) t1
  104. where park_id in ('100106091','100105564')