Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select
- rmonth,rmonth2, ncars, wtotal_ncars
- from (
- select rmonth,rmonth2,
- (select count(cz.id) from car_zone_logs cz, zones z
- 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
- ) as ncars,
- (select count(cz.id) from car_zone_logs cz, zones z
- 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
- ) as wtotal_ncars
- from (
- select
- rmonth,rmonth2, min(date_format(rret,"%Y-%m-%d")) as mfirst, max(date_format(rret,"%Y-%m-%d")) as mlast
- from (
- select
- concat(year(r.return_at+interval 8 hour), "-", lpad(month(r.return_at+interval 8 hour),2,"0")) as rmonth,
- month(r.return_at+interval 8 hour) as rmonth2,
- r.start_at+interval 8 hour as rst, r.end_at+interval 8 hour as rend, r.return_at+interval 8 hour as rret
- from reservations r, members m, zones z
- where
- r.state='completed'
- and r.member_id=m.id
- and m.imaginary in ('normal', 'sofam')
- and r.start_zone_id=z.id
- and r.start_zone_id not in (2,3,101,383,378,697,712,818,786)
- ) temp
- group by rmonth
- ) temp
- group by rmonth
- ) temp
- group by rmonth
Advertisement
Add Comment
Please, Sign In to add comment