park_bahavior.txt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. -- 停车时长分析
  2. SELECT
  3. case when a.out_time-t.in_time <= 7200 then 0
  4. when a.out_time-t.in_time > 7200 and a.out_time-t.in_time <= 14400 then 2
  5. when a.out_time-t.in_time > 14400 and a.out_time-t.in_time <= 28800 then 4
  6. when a.out_time-t.in_time > 28800 and a.out_time-t.in_time <= 43200 then 8
  7. when a.out_time-t.in_time > 43200 then 12
  8. end as hour_flag,
  9. count(t.order_no) as order_num
  10. FROM
  11. luo_parking_inrecord t
  12. INNER JOIN luo_parking_outrecord a
  13. ON t.order_no = a.order_no
  14. group by 1
  15. -- 停车时段分析
  16. select
  17. a.hour_group,
  18. a.park_in_num, -- 入场数量
  19. b.park_out_num -- 出场数量
  20. from
  21. (select
  22. case when hour(in_time)>=0 and hour(in_time)<3 then 3
  23. when hour(in_time)>=3 and hour(in_time)<6 then 6
  24. when hour(in_time)>=6 and hour(in_time)<9 then 9
  25. when hour(in_time)>=9 and hour(in_time)<12 then 12
  26. when hour(in_time)>=12 and hour(in_time)<15 then 15
  27. when hour(in_time)>=15 and hour(in_time)<18 then 18
  28. when hour(in_time)>=18 and hour(in_time)<21 then 21
  29. when hour(in_time)>=21 and hour(in_time)<24 then 24 end hour_group,
  30. count(parking_no) as park_in_num
  31. from
  32. luo_parking_inrecord t
  33. group by 1
  34. order by 1) a
  35. left join
  36. (select
  37. case when hour(out_time)>=0 and hour(out_time)<3 then 3
  38. when hour(out_time)>=3 and hour(out_time)<6 then 6
  39. when hour(out_time)>=6 and hour(out_time)<9 then 9
  40. when hour(out_time)>=9 and hour(out_time)<12 then 12
  41. when hour(out_time)>=12 and hour(out_time)<15 then 15
  42. when hour(out_time)>=15 and hour(out_time)<18 then 18
  43. when hour(out_time)>=18 and hour(out_time)<21 then 21
  44. when hour(out_time)>=21 and hour(out_time)<24 then 24 end hour_group,
  45. count(parking_no) as park_out_num
  46. from
  47. luo_parking_outrecord t
  48. group by 1) b
  49. on a.hour_group=b.hour_group
  50. -- 临时停车分析
  51. SELECT
  52. CASE
  53. WHEN a.out_time - t.in_time <= 86400 THEN '短期'
  54. else '长期' END AS temporary_parking_flag,
  55. count( t.order_no ) AS order_num
  56. FROM luo_parking_inrecord t
  57. INNER JOIN luo_parking_outrecord a
  58. ON t.order_no = a.order_no
  59. group by 1
  60. -- 夜间停车分析
  61. SELECT
  62. CASE
  63. WHEN hour(in_time)>=6 and hour(in_time)<18 THEN '白天'
  64. else '夜间' END AS temporary_parking_flag,
  65. count( t.order_no ) AS order_num
  66. FROM luo_parking_inrecord t
  67. INNER JOIN luo_parking_outrecord a
  68. ON t.order_no = a.order_no
  69. group by 1