简体   繁体   English

获得在到达和离开日期之间的价格可用的房间

[英]Get available room with rates between arrival and departure date

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. 我想获取所有符合条件的房间,其可用性应等于或大于请求的入住日期和退房日期之间所请求的房间数量(即no_of_rooms> = 3)。 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: 您可以使用添加了AND条件的查询来使用:

 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM