Advertisement
ahmedrahil786

Mineng Query - Reservations Between a certain time Period

Aug 23rd, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. use socar_malaysia;
  2. select
  3. r.id, r.member_id, m.first_name, m.last_name, r.way, r.state, r.start_zone_id as zone_id, z.city as city, z.region as region, z.name as zone_name, r.car_id, c.registration_no, cs.car_name as cartype,
  4. convert_tz(r.created_at, '+00:00', '+8:00') as rc, convert_tz(r.start_at, '+00:00', '+8:00') as rs, convert_tz(r.end_at, '+00:00', '+8:00') as re,
  5. (timestampdiff(minute, r.start_at, r.end_at)/60) as dur,
  6. ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind='rent'),0) as rent,
  7. ifnull((select sum(amount) from charges where state='normal' and r.id=reservation_id and kind in ('rent','d2d','mileage')),0)
  8. - ifnull((select sum(amount) from payments where state='normal' and reservation_id=r.id and paid_type ='coupon'),0) as nr
  9.  
  10. from reservations r, zones z, members m, car_classes cs, cars c
  11. where
  12. r.start_zone_id = z.id
  13. and r.member_id = m.id
  14. and c.id = r.car_id
  15. and c.car_class_id = cs.id
  16. and m.imaginary in ('sofam', 'normal')
  17. and m.state in ('normal')
  18. and z.state in ('normal')
  19. and r.state in ('inuse','completed')
  20.  
  21. #return cases
  22. and convert_tz(r.return_at, '+00:00', '+8:00') between '2019-08-22 20:00:00' and '2019-08-23 01:00:00'
  23.  
  24. #reservation start cases
  25. #and convert_tz(r.start_at, '+00:00', '+8:00') between '2019-08-22 20:00:00' and '2019-08-23 01:00:00'
  26.  
  27. #inuse case
  28. #and convert_tz(r.start_at, '+00:00', '+8:00') < '2019-08-22 20:00:00'
  29. #and convert_tz(r.end_at, '+00:00', '+8:00') > '2019-08-23 01:00:00'
  30.  
  31. group by r.id
  32. order by re desc
  33. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement