Mysql query to retrieve record using between for two dates

user2660409 picture user2660409 · Aug 7, 2013 · Viewed 27.2k times · Source

I have one requirement and i am totally confused how to write the query. I am a fresher in this company so please help me

User will select the following Dates:

Ex: fromDate: 2013-08-02 toDate: 2013-09-03 (YYYY-MM-DD)

id  resort_id   room_id Date1       Date2       price
5   35      45          2013-11-01  2013-11-30  3000.00
6   35      50          2013-07-25  2013-08-25  2000.00
7   35      541         2013-07-25  2013-08-25  4000.00
8   35      541         2013-08-26  2013-09-26  4000.00

Now i should get price based result for each date or sum of the price for both the date group by room id

Expected result

id  resort_id   room_id     Date1       Date2       price
6   35      50              2013-07-25  2013-08-25  2000.00
7   35      541             2013-07-25  2013-08-25  4000.00
8   35      541             2013-08-26  2013-09-26  4000.00

OR

id  resort_id      room_id  price
6   35             50       2000.00
7   35             541      8000.00

Answer

Raja Ram T picture Raja Ram T · Apr 2, 2014
SELECT * FROM lr_price_peak_rates  WHERE  `from_date`>='2014-04-08' AND `to_date`<='2014-04-30' 

try the above query it can be working fine