Sql 查找日期板之间的记录(范围)
我创建了一个表格,在表格中输入了酒店的价格,以及这些价格有效的日期。如果我在特定酒店的价格中选择了特定日期,我希望在另一种形式中显示的是属于任何日期板下的特定日期,因为每个日期板都有不同的酒店价格 我试过这个Sql 查找日期板之间的记录(范围),sql,date,Sql,Date,我创建了一个表格,在表格中输入了酒店的价格,以及这些价格有效的日期。如果我在特定酒店的价格中选择了特定日期,我希望在另一种形式中显示的是属于任何日期板下的特定日期,因为每个日期板都有不同的酒店价格 我试过这个 select * from test_hotelrates where Datefrom >= convert(date, '2013-10-01', 103) and Dateto <= convert(date, '2013-10-31', 103) and Season
select * from test_hotelrates where Datefrom >= convert(date, '2013-10-01', 103)
and Dateto <= convert(date, '2013-10-31', 103) and Season = 'Season'
select*from test_hotelrates其中Datefrom>=convert(日期,'2013-10-01',103)
和Dateto它不起作用,因为您使用两个不同的日期进行比较。在本例中,您需要10月份所有天数的费率。我猜有人想在酒店住一个月。但我想你应该在这段时间内每天检查一下,看看当前的汇率。因为在这段时间里,利率可能会发生变化
您的查询将只返回2013年1月10日至2013年1月31日期间的费率
我认为您需要进行不同的查询或多次运行此查询
select * from test_hotelrates where Datefrom <= convert(date, '2013-10-01', 103)
and Dateto >= convert(date, '2013-10-01', 103) and Season = 'Season'
select * from test_hotelrates where Datefrom <= convert(date, '2013-10-02', 103)
and Dateto >= convert(date, '2013-10-02', 103) and Season = 'Season'
select * from test_hotelrates where Datefrom <= convert(date, '2013-10-03', 103)
and Dateto >= convert(date, '2013-10-03', 103) and Season = 'Season'
test_hotelrates中选择*,其中Datefrom=convert(日期,'2013-10-01',103)和seasure='seasure'
从test_hotelrates中选择*,其中Datefrom=convert(日期,'2013-10-02',103)和Season='Season'
从test_hotelrates中选择*,其中Datefrom=convert(日期,'2013-10-03',103),Season='Season'
等等。更改您的查询,如下所示:
select * from test_hotelrates where convert(varchar(10),Datefrom,103) >= convert(varchar(10), '2013-10-01', 103)
and convert(varchar(10),Dateto,103) <= convert(varchar(10), '2013-10-31', 103) and Season = 'Season'
select*from test_hotelrates,其中convert(varchar(10),Datefrom,103)>=convert(varchar(10),'2013-10-01',103)
和转换(varchar(10),Dateto,103)