SQL 查询时间区间解决方法
SQL 查询时间区间表tableHTML code表 tableid日期仓库费用12011-01-011322011-01-021232011-06-011742011-
SQL 查询时间区间
表 table
HTML code表 tableid 日期 仓库 费用1 2011-01-01 1 32 2011-01-02 1 23 2011-06-01 1 74 2011-02-01 2 125 2011-02-05 2 1
怎样查询日期在 2011-06-25 -- 2011-07-24 之间的数据,如果查不到, 就查询2011-05-25 -- 2011-06-24之间的数据,如果还查不到 就依次类推,知道查询到为止,
[解决办法]IF...ELSE
[解决办法]if exists(select 1 from tb where 日期 between '2011-06-25' and '2011-07-24')
begin
select * from tb where 日期 between '2011-06-25' and '2011-07-24'
end
else
if exists(select 1 from tb where 日期 between '2011-05-25' and '2011-06-24')
begin
select * from tb where 日期 between '2011-05-25' and '2011-06-24'
end