ahmedrahil786

Cars and Respective Ride Lengths for a month - Date Select

Mar 12th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. select
  2.  
  3. cc.car_name as carname,
  4. sum(TIMESTAMPDIFF(hour,CONVERT_TZ(r.start_at, '+00:00', '+8:00'),CONVERT_TZ(r.end_at, '+00:00', '+8:00'))) as ridelength
  5.  
  6. from reservations r
  7.  
  8. join cars c
  9. on c.id = r.car_id
  10.  
  11. join car_classes cc
  12. on cc.id = c.car_class_id
  13.  
  14.  
  15. where CONVERT_TZ(r.start_at, '+00:00', '+8:00') >= '2019-1-1 00:00'
  16. and CONVERT_TZ(r.start_at, '+00:00', '+8:00') <= '2019-1-31 00:00'
  17. and r.state = 'completed'
  18.  
  19. group by cc.car_name
Advertisement
Add Comment
Please, Sign In to add comment