sql - MySQL rooms availability for range -


i want select rooms within selected date range have @ least 1 available day. if user want select 2014-06-15 - 2014-06-30 should not rooms full available within period rooms available 1 more days.

i have 2 tables 'rooms' , 'rooms_booking'

tables:

rooms ( id, title, beds_number...)   rooms_booking(id, rooms_id, start, end)   

how should retrieve rooms criteria described above? thanks

just days taken , infer room has @ least 1 day available.

select a.title, ifnull(sum(datediff(least(b.end, '2014-06-30'), a.start) + 1),0) days_taken rooms left join rooms_booking b on a.id = b.rooms_id b.start >= '2014-06-15' , b.start <= '2014-06-30' group a.title having days_taken <= datediff('2014-06-30', '2014-06-15'); 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -