Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ######################################################################################
- # # of car used for each day
- select temp.rday,
- (select count(czl.id) from car_zone_logs czl where rday=date_format(czl.log_date, "%Y-%m-%d") and czl.zone_state='normal') as ncars,
- temp.ncars_used,
- (select count(distinct car_id) from reservations r, members m
- where r.state = 'completed'
- and date_format(r.return_at+interval 8 hour, "%Y-%m-%d") = temp.rday
- and r.member_id=m.id
- and m.imaginary in ('sofam', 'normal')
- and r.start_zone_id not in (2,3,101)
- ) ncar_returned
- from (
- select rday,count(distinct cid) as ncars_used
- from (select date_format(dt.rday, "%Y-%m-%d") as rday, resv.rid as rid, resv.cid as cid, resv.rsh as rsh, resv.reh as reh
- from (select concat(date_format(r.return_at+interval 8 hour, "%Y-%m-%d"), " 00:00:00") as rday from reservations r
- where r.return_at is not null and r.return_at+interval 8 hour > "2019-05-01 00:00:00"
- group by rday
- ) dt,
- (select r.id as rid, r.car_id as cid, r.start_at+interval 8 hour as rsh, r.end_at+interval 8 hour as reh
- from reservations r, members m
- where r.member_id=m.id
- and m.imaginary in ('sofam', 'normal')
- and r.state in ('completed', 'inuse')
- and r.start_zone_id not in (2,3,101)
- and r.end_at+interval 8 hour >= "2019-05-01"
- ) resv
- where resv.rsh < (dt.rday+interval 1 day) and resv.reh > dt.rday) temp
- group by rday
- order by rday desc) temp;
Advertisement
Add Comment
Please, Sign In to add comment