Hi again!
I have a new requirement now.
Apart from the orders table, I have another table (special_dates) from where the startdate and end date has to be fetch and considered those dates as to be booked,
The DDL for special_dates:
Code:
CREATE TABLE `special_dates` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` VARCHAR(100) DEFAULT NULL,
`start_date` DATE DEFAULT NULL,
`end_date` DATE DEFAULT NULL,
`rooms_to_book` INT(5) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MYISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
EDIT: The dates entered in this table shall also be considered as BOOKED dates for the number of cottages specified in the "rooms_to_book" column.
To understand more on what I am looking for, here is what I have modified your query to get the result but apparently its not working.
Code:
SELECT A.theDate, COUNT(*) AS reservations
FROM allDates AS A, orders AS O, special_dates as S
WHERE ( (A.theDate BETWEEN O.date_from AND O.date_to) OR (A.theDate BETWEEN P.start_date AND P.end_date))
AND A.theDate BETWEEN '2010-12-1' AND '2010-12-31'
GROUP BY A.theDate
HAVING COUNT(*) = 8
ORDER BY A.theDate
It returns me rows with insane reservations counts.
Could you please help me again?
Many thanks
PS: The allDates table contains all dates between 2010-12-01 to 2020-12-31