1

roomtype次のデータを含むテーブルがあります。

Hotel_ID    Name     Rate   Season    StartSeason   EndSeason
   1      Deluxe/Ac  2700   New Year  2013-12-20    2014-01-10
   1      Deluxe/Ac  3100   31 Dec    2013-12-31    2012-12-31
   1      Deluxe/Ac  1700   Diwali    2013-11-01    2013-11-15
   1      Deluxe/Ac  800    Normal    NULL          NULL

特定の日付 (つまり2013-11-09) について、一致する季節の を返したいrateと思います。ここで、特定の日付は StartSeason と EndSeason の日付内にあります。

つまり、日付が2013-11-09の場合、レートは 1700 になります。日付が2012-09-09の場合、レートは 800 になります。

ストアド プロシージャを作成したり、SQL クエリを記述したりするにはどうすればよいですか?

4

3 に答える 3

2
select top 1 hotel_id, rate
from roomtype r
where '2013-11-09' between startseason and endseason
or startseason is null and endseason is null
order by case when startseason is null and endseason is null then 2 else 1 end
于 2013-09-21T10:56:08.557 に答える