Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql query to retrieve record using between for two dates

Tags:

mysql

between

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
like image 419
user2660409 Avatar asked Mar 12 '26 06:03

user2660409


1 Answers

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

like image 50
Raja Ram T Avatar answered Mar 14 '26 07:03

Raja Ram T