【发布时间】:2013-03-10 10:53:36
【问题描述】:
我需要选择入住日期和退房日期在指定日期范围之间的房价。这些费率根据其条件分别命名。房间费用取决于所选日期。这是我的代码:
rate_eb
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
条件是:
- 预订必须介于 rate_starts 和 rate_ends 之间。
- 总住宿天数必须大于或等于 rate_min_stay。
- rate_discount 是来自另一个表的主费率的折扣百分比。如果总价为 100,则此预订将应用 80 的价格。
现在,我想从 rate_db 中获取具有日期范围的数据 - 特别是对于 rate_discount。这是我的 mySQL:
select rate_discount
from rate_eb
where rate_min_stay<='4'
and reb_starts>='2013-06-19'
and reb_ends<='2013-06-23'
从上面的代码。我预计 淡季 的 rate_discount=20,但选择了所有小于或等于 4 的价格。
现在,请给我建议解决方案。如何重新编写代码以访问 rate_starts 和 rate_ends 之间的 rate_discount。
【问题讨论】:
-
表描述有
rate_starts,而查询有reb_date1。是不是打错字了? -
@ypercube,哦,这是我的错。我用 mySQL 测试过,忘记改了。现在变了。