求教一条SQL语句!
1.我的数据库是ACCESS数据库,里面有1个日期字段,如
2007-08-11 08:25:30
2007-08-12 14:25:30
2007-08-13 11:25:30
2007-08-14 17:25:30
2007-08-15 16:25:30
2007-08-16 15:25:30
2007-08-17 14:25:30
2007-08-18 17:25:30
我想查询2007-08-11到2007-08-18日期范围内14:00:00 到16:30:00的数据,如何写SQL语句,其结果返回如下:
2007-08-12 14:25:30
2007-08-15 16:25:30
2007-08-16 15:25:30
2007-08-17 14:25:30
[解决办法]
declare @t table(dt datetime)
insert into @t
select '2007-08-11 08:25:30 '
union all select '2007-08-12 14:25:30 '
union all select '2007-08-13 11:25:30 '
union all select '2007-08-14 17:25:30 '
union all select '2007-08-15 16:25:30 '
union all select '2007-08-16 15:25:30 '
union all select '2007-08-17 14:25:30 '
union all select '2007-08-18 17:25:30 '
select * from @t
select * from @t where dt> = '2007-08-11 14:00:00 ' and dt <= '2007-08-18 16:30:00 '
原始数据:
------
2007-08-11 08:25:30.000
2007-08-12 14:25:30.000
2007-08-13 11:25:30.000
2007-08-14 17:25:30.000
2007-08-15 16:25:30.000
2007-08-16 15:25:30.000
2007-08-17 14:25:30.000
2007-08-18 17:25:30.000
运行结果:
------
2007-08-12 14:25:30.000
2007-08-13 11:25:30.000
2007-08-14 17:25:30.000
2007-08-15 16:25:30.000
2007-08-16 15:25:30.000
2007-08-17 14:25:30.000