MySQL:如何在MySQL的两个日期之间选择开始日期和结束日期的记录
我需要选择入住日期和退房日期在指定日期范围内的房价。这些费率根据其条件单独命名。房间费用取决于所选日期。这是我的密码: 评级MySQL:如何在MySQL的两个日期之间选择开始日期和结束日期的记录,mysql,sql,select,Mysql,Sql,Select,我需要选择入住日期和退房日期在指定日期范围内的房价。这些费率根据其条件单独命名。房间费用取决于所选日期。这是我的密码: 评级 rate_name rate_starts rate_ends rate_discount rate_min_stay --------------------------------------------------------------------------- Low Season 2013-05-01 2013-
rate_name rate_starts rate_ends rate_discount rate_min_stay
---------------------------------------------------------------------------
Low Season 2013-05-01 2013-10-31 20 3
High Season1 2013-11-01 2013-12-19 20 4
High Season2 2013-02-21 2013-04-31 20 4
Peak Season 2013-12-20 2014-02-20 20 5
条件为:
select rate_discount
from rate_eb
where rate_min_stay<='4'
and reb_starts>='2013-06-19'
and reb_ends<='2013-06-23'
选择费率\折扣
来自rate_eb
何处房价最低停留时间='2013-06-19'
而reb_ends我假设访问者可以输入一个时段,而不仅仅是一个日期。如果该时期的开始日期在淡季,结束日期在旺季,会发生什么情况?那么你想看哪种利率
select rate_discount
from rate_eb
where rate_min_stay <= abs( datediff( reb_date2, reb_date1 ) )
and reb_date1 between rate_starts and rate_ends
and reb_date2 between rate_starts and rate_ends
选择费率\折扣
来自rate_eb
其中rate_min_stay使用to_date('dateInString','format')将reb_date1和reb_date2的字符串转换为日期,如果要对rate_min_stay进行大于的比较,则直接使用不带引号的数值表说明具有rate_start
,而查询具有reb_date1
。那是打字错误吗?@ypercube,哦,是我的错。我用mySQL测试了它,但忘了更改它。现在它变了。嗨,Vivienne,你的代码看起来更有价值,但是mySQL不接受date_diff()函数。我检查了phpmyadmin版本-3.5.7。知道吗?抱歉,将代码更新为正确的方法(datediff()而不是date_diff())Vivienne,你的解决方案有效!感谢您的关注:)