-3

我有一张价格房间的桌子,

有三个季节(默认,低,高),我想按两个日期搜索以获得不同日期,季节的总价格..

这是我的表和查询

http://sqlfiddle.com/#!2/7ebc2/1

如何计算5天(mysql)酒店预订系统的总价

select sum(coalesce(prices.room_price , def.room_price) ) as TotalPrice
from (select strtotime('2013-05-07' , '%Y-%m-%d') as thedate union all
      select strtotime('2013-05-08' , '%Y-%m-%d') as thedate
     ) dates left outer join
     SH_rooms_price prices
     on dates.thedate between prices.start_season and prices.end_season and
        dayname(dates.thedate) = prices.day_of_week join SH_rooms_price def
    on def.season_price = 'default' and
       def.id_hotel = 5544 and
       def.day_of_week = dayname(dates.thedate)

出现错误:strtotime 不存在

4

2 回答 2

1

strtotime 不是 mysql 中的有效函数。它仅针对 php 定义。尝试使用STR_TO_DATE

修改后的查询工作正常。

select sum(coalesce(prices.room_price , def.room_price) ) as TotalPrice
from (select str_to_date('2013-05-15' , '%Y-%m-%d') as thedate union all
      select str_to_date('2013-05-08' , '%Y-%m-%d') as thedate
     ) dates left outer join
     SH_rooms_price prices
     on dates.thedate between prices.start_season and prices.end_season and
        dayname(dates.thedate) = prices.day_of_week join SH_rooms_price def
    on def.season_price = 'default' and
       def.id_hotel = 5544 and
       def.day_of_week = dayname(dates.thedate);

. 查看SQLFiddle

于 2013-04-25T11:22:26.377 回答
0

strtotime 是一个 PHP 函数,而不是 mySQL 函数。

于 2013-04-25T11:20:10.577 回答