not quite. the where clause selects all of the rows in that date range, regardless of the status. the qhole query is grouped by the property_id. then the count(*)... line counts the number of rows for that property, then i subtract out the number of rows with a status of 1 or 5. finally, the having clause removes all rows where the property has no unavailable dats in that range.
if that didn't make sense, run this query instead. compare the query to the one i posted above to see what i changed. i think that will help you figure out what's going on:
Code:
select property_id
, count(*) as avail
, sum(case status when 1 then 1 when 5 then 1 else 0 end) as unavail
from tbl_availability
where ddate between '$arrival_date' and '$dep_date'
group
by property_id
Bookmarks