यह सही परिणाम देना चाहिए:
select
id,
min(startDate) as startFreeDate,
count(*) - (endDate is null) numFreeDays
from (
select
pb1.id,
pb1.bookingDate startDate,
min(pb2.bookingDate) endDate
from
pricesBookings pb1 left join pricesBookings pb2
on pb1.id=pb2.id
and pb2.price>0
and pb2.bookingDate>pb1.bookingDate
where
pb1.price=0
group by
pb1.id,
pb1.bookingDate
) s
group by id, endDate
order by id, startDate
इसे देखें यहां ।
यदि आपको सभी मुफ्त स्लॉट खोजने की आवश्यकता है, उदाहरण के लिए, 14 दिन, तो आप HAVING जोड़ सकते हैं:
group by id, endDate
having count(*) - (endDate is null) >= 14
order by id, startDate