Price plan master table
CREATE TABLE `price_plan_master` (
`id` int(11) NOT NULL COMMENT 'Id ( Auto Increment )',
`room_id` int(11) NOT NULL COMMENT 'Room Id (Related to room_master table)',
`date` date NOT NULL COMMENT 'Date to get rate',
`no_of_rooms` int(11) NOT NULL COMMENT 'No of rooms available',
`rate` double NOT NULL COMMENT 'Room rate',
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Id|room_id|date|no_of_rooms|rate
1|2|2017-10-01|5|8530
2|2|2017-10-02|5|8530
3|3|2017-10-01|5|8200
4|3|2017-10-02|5|8200
5|2|2017-10-01|2|14609
6|2|2017-10-02|2|14609
7|3|2017-10-03|2|14609
8|2|2017-10-04|2|14609
9|3|2017-10-01|2|13000
10|3|2017-10-02|2|13000
11|3|2017-10-03|2|13000
12|3|2017-10-04|2|13000
13|6|2017-10-01|3|17286
14|6|2017-10-02|3|17286
15|6|2017-10-03|3|17286
16|6|2017-10-04|3|17286
17|11|2017-10-01|10|2830
18|11|2017-10-02|10|2830
19|11|2017-10-03|10|2830
20|11|2017-10-04|10|2830
21|12|2017-10-01|2|1700
I want to fetch all rooms with conditions availability should be equals to or maximum requested no of rooms (means no_of_rooms >= 3) between requested check in and check out date. For every date between date range room availability should be checked.
Currently, I am using below query.
select * from price_plan_master
where date >= checkin and date <= checkout
I need to check availability for all dates.
Can anyone suggest what should I change in single query to fetch records ?
You can use the query you have written with an added AND condition:
select * from price_plan_master
where date >= checkin and date <= checkout
and no_of_rooms >= 3
This will select all rooms in the date range where the number of rooms is greater than or equal to the requested number of rooms.
SELECT ppm。* FROM price_plan_master ppm INNER JOIN(SELECT room_id,COUNT(room_id)AS cnt,DATEDIFF(checkout,checkin)+1 AS TEMP FROM price_plan_master WHERE date
> = checkin AND date
<= checkout AND no_of_rooms> = 3 GROUP BY room_id正在cnt =温度)t ON ppm.room_id = t.room_id
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.