ahmedrahil786

Loui query to map the number of cars - To Daily index file

Jun 12th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. select
  2. rmonth,rmonth2, ncars, wtotal_ncars
  3.  
  4. from (
  5. select rmonth,rmonth2,
  6. (select count(cz.id) from car_zone_logs cz, zones z
  7. where cz.zone_id=z.id and z.id not in (2,3,101,383,378,712,818,786) and date_format(date_sub(cz.log_date, interval 1 day)+interval 8 hour, "%Y-%m-%d")=mlast
  8. ) as ncars,
  9. (select count(cz.id) from car_zone_logs cz, zones z
  10. where cz.zone_id=z.id and z.id not in (2,3,101,383,378,712,818,786) and date_sub(cz.log_date, interval 1 day)+interval 8 hour >= mfirst and date_sub(cz.log_date, interval 1 day)+interval 8 hour < mlast+interval 1 day
  11. ) as wtotal_ncars
  12.  
  13. from (
  14.  
  15. select
  16. rmonth,rmonth2, min(date_format(rret,"%Y-%m-%d")) as mfirst, max(date_format(rret,"%Y-%m-%d")) as mlast
  17.  
  18. from (
  19. select
  20. concat(year(r.return_at+interval 8 hour), "-", lpad(month(r.return_at+interval 8 hour),2,"0")) as rmonth,
  21. month(r.return_at+interval 8 hour) as rmonth2,
  22. r.start_at+interval 8 hour as rst, r.end_at+interval 8 hour as rend, r.return_at+interval 8 hour as rret
  23. from reservations r, members m, zones z
  24. where
  25. r.state='completed'
  26. and r.member_id=m.id
  27. and m.imaginary in ('normal', 'sofam')
  28. and r.start_zone_id=z.id
  29. and r.start_zone_id not in (2,3,101,383,378,697,712,818,786)
  30. ) temp
  31. group by rmonth
  32. ) temp
  33. group by rmonth
  34. ) temp
  35. group by rmonth
Advertisement
Add Comment
Please, Sign In to add comment