php - retrieve unique hotel id for users for booking system -


i have sql related problem. need write complex query table described below

id  date        quantity    roomtypeid  hotelid 

user search hotels using check in , check out date , specify numbers of room(quantity) search query, need hotel ids above table have minimum number of rooms available check in check out date.

1   04-01-2013  3   4   10 2   04-02-2013  3   4   10 3   04-03-2013  3   4   10 4   04-04-2013  3   4   10 5   04-01-2013  3   4   11 6   04-02-2013  3   4   11 7   04-03-2013  3   4   11 8   04-04-2013  3   4   11 9   04-01-2013  3   4   12 10  04-02-2013  3   4   12 

the resulting query should give 10,11 hotel id if user wants book 04-01-2013 04-03-2013 3 rooms.

regards subash

update2

select `hotelid`    table1  `date` between '2013-04-01' , '2013-04-03'    , quantity >=3  group `hotelid` having count(*) = datediff('2013-04-03', '2013-04-01') + 1 

3 in where clause number of rooms should available.

output

| hotelid | ----------- |      10 | |      11 | 

sqlfiddle


Comments