strtodate mysql函数不存在.. mysql查询

时间:2013-04-25 11:12:21

标签: mysql sql

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

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

这是我的表和查询

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

how can calculate the total price for 5 days (mysql ) hotel booking system

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不存在

2 个答案:

答案 0 :(得分: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

答案 1 :(得分:0)

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