ahmedrahil786

No of Cars avbailable at a certain Hour - Leon

Mar 12th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. select
  2. r.id as rid,
  3. r.state as status,
  4. #c.id as carid,
  5. #cc.id as carclassid,
  6. z.region as zonename,
  7. date(r.occupy_start_at + interval '8' hour) as day,
  8. TIMESTAMPDIFF(hour,CONVERT_TZ(r.start_at, '+00:00', '+8:00'),CONVERT_TZ(r.end_at, '+00:00', '+8:00')) as ridelength,
  9. hour(r.occupy_start_at + interval '8' hour) as startingtime,
  10. #TIMESTAMPDIFF(minute,r.start_at + interval '8' hour,r.end_at + interval '8' hour) as ridelengthinminutes,
  11. cc.car_name as carname,
  12. count(distinct case when r.state = 'completed' then r.id end) as Bookings,
  13. count(distinct case when CONVERT_TZ(r.start_at, '+00:00', '+8:00') <= '2019-1-05 10:00'
  14. and CONVERT_TZ(r.end_at, '+00:00', '+8:00') >= '2019-1-05 10:05' then r.id end) as 10pm
  15. from cars as c
  16.  
  17. join car_classes as cc
  18. on c.car_class_id = cc.id
  19.  
  20. join zones as z
  21. on z.id = c.zone_id
  22.  
  23. join reservations as r
  24. on r.car_id = c.id
  25.  
  26. join payments as p
  27. on p.reservation_id = r.id
  28.  
  29. where CONVERT_TZ(r.start_at, '+00:00', '+8:00') >= '2019-1-1 00:00'
  30. and CONVERT_TZ(r.start_at, '+00:00', '+8:00') <= '2019-1-31 00:00'
  31.  
  32. group by car_id, r.occupy_start_at + interval '8' hour,weekday(r.occupy_start_at + interval '8' hour),r.id,z.name
Advertisement
Add Comment
Please, Sign In to add comment