Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select lid as lid,car_brand as car_brand, car_model as car_model,
- Date(temp.firstdate) as firstbooking,
- (select min(Date(request_start_at)) from bookings b where temp.lid = b.listing_id and (b.request_start_at) > temp.firstdate) as secondbooking
- from
- (select distinct l.id as lid,
- br.name as car_brand, m.name as car_model,
- min(b.request_start_at) as firstdate
- from bookings b
- left join listings l on b.listing_id = l.id
- left join models m on l.model_id = m.id
- left join brands br on m.brand_id = br.id
- where b.status = 'completed'
- group by 1,2,3) temp
- order by 1 asc
Advertisement
Add Comment
Please, Sign In to add comment