-3

私は価格部屋のテーブルを持っています、

3 つの季節 (デフォルト、低、高) があります。2 つの日付で検索して、異なる日、季節の合計価格を取得したいと考えています。

これは私のテーブルとクエリです

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 に答える