我的数据库中的数据:明细号      账号            存入金额       存入日期         取出金额      取出日期
  1          1                102         2010-12-02                 
  2          1                                                 11        2010-12-03
  3          1                102         2010-12-03                 
  4          1                                                 12        2010-12-04以上就是我的数据库中的交易记录数据,现在我想查出在某段时间内的交易详情:
 
比如我想查在  大于 2010-12-02  而小于 2010-12-04 时间的交易,即应该显示出  2          1                                                 11        2010-12-03
  3          1                102         2010-12-03                 这两条数据,求Sql语句

解决方案 »

  1.   

    select * 
    from tb
    where (存入日期>='2010-12-02' and 存入日期<'2010-12-04')
    or (取出日期>='2010-12-02' and 取出日期<'2010-12-04')
      

  2.   

    select * from tb where 日期 between dateadd(day,1,'2010-12-02') and dateadd(day,-1,'2010-12-02')  
      

  3.   

    select * from tb where 存入日期 between dateadd(day,1,'2010-12-02') and dateadd(day,-1,'2010-12-02')  
    union all
    select * from tb where 取出日期
     between dateadd(day,1,'2010-12-02') and dateadd(day,-1,'2010-12-02')