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

解决方案 »

  1.   

    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 @tselect * 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
      

  2.   

    更正一下:
    select * from @tselect * from @t where dt>='2007-08-11 14:00:00' and dt<='2007-08-18 16:30:00'要是这样查询的话,比如2007-08-12 16:35:10这条数据肯定要查进去了
    我的目的是:这段日期段只有14:00:00到16:30:00时间段把他查询出来'
    思路我知道:
    应该要把这个日期字段分成两部分进行查询, 就是不知道SQL怎么写,谢谢楼上的回答.