Reputation: 43
I am working in hotel domain. i was created the inventory page for each hotel along with each rooms.
In data structure of db i have created with start date and end date. while inventory we pass the record in between dates.
SELECT `crs_room_type_detail`.*, `crs_room_type`.`room_type_name`
FROM (`crs_room_type_detail`)
JOIN `crs_room_type` ON `crs_room_type_detail`.`room_type_id` = `crs_room_type`.`room_type_id`
WHERE `crs_room_type_detail`.`hotel_id` = '4'
AND `crs_room_type_detail`.`sdate` >= '2016-09-21'
AND `crs_room_type_detail`.`edate` <= '2016-10-04'
GROUP BY `crs_room_type_detail`.`room_type_id`
This the query to get the result.
for Rooms we had the sdate : 2016-09-20 and edate : 2016-09-30 this criteria it wont work, suppose i changes condition like sdate
<= '2016-09-21' and edate
>= '2016-10-04' its wont work some other criteria
Upvotes: 1
Views: 116
Reputation: 807
Try This One
SELECT `crs_room_type_detail`.*, `crs_room_type`.`room_type_name`
FROM (`crs_room_type_detail`)
JOIN `crs_room_type` ON `crs_room_type_detail`.`room_type_id` = `crs_room_type`.`room_type_id`
WHERE `crs_room_type_detail`.`hotel_id` = '4'
AND `crs_room_type_detail`.`sdate` BETWEEN '2016-09-21' AND '2016-10-04'
AND `crs_room_type_detail`.`edate` BETWEEN '2016-09-21' AND '2016-10-04'
GROUP BY `crs_room_type_detail`.`room_type_id`
Upvotes: 1
Reputation: 46
use between to get date range:
SELECT `crs_room_type_detail`.*, `crs_room_type`.`room_type_name`
FROM (`crs_room_type_detail`)
JOIN `crs_room_type` ON `crs_room_type_detail`.`room_type_id` = `crs_room_type`.`room_type_id`
WHERE `crs_room_type_detail`.`hotel_id` = '4'
AND `crs_room_type_detail`.`sdate` between '2016-09-21' and '2016-10-04'
GROUP BY `crs_room_type_detail`.`room_type_id`
Upvotes: 1
Reputation: 670
Try out the following script:
SELECT `crs_room_type_detail`.*, `crs_room_type`.`room_type_name`, date
FROM (`crs_room_type_detail`)
JOIN `crs_room_type` ON `crs_room_type_detail`.`room_type_id` =
`crs_room_type`.`room_type_id`
WHERE `crs_room_type_detail`.`hotel_id` = '4'
AND date(`crs_room_type_detail`.`sdate`) >= date('2016-09-21')
AND date(`crs_room_type_detail`.`edate`) <= date('2016-10-04')
GROUP BY `crs_room_type_detail`.`room_type_id`
Upvotes: 1