要查询最近6个月的数据,比如现在是2010年9月,那我就查询2010年4-9月的数据, 如果现在是2011年3月那就查询2010-10月,11月,12月,2011年1月,2月,3月的数据, 请问查询语句怎么写??

解决方案 »

  1.   

    Where DateDiff(mm,字段,GetDate())<= 6
      

  2.   

    用datediff(mm,时间字段,当前时间)函数可以实现
      

  3.   

    select * from record where datediff(mm,date,GetDate())<=6
      

  4.   

    select * from record where datediff(mm,date,GetDate())<=6
      

  5.   

    当前时间往前6个月还有一个办法就是先计算,然后用 between '' and ''比datediff(mm,date,GetDate())<=6要快点
      

  6.   

    Where DateDiff(mm,字段,GetDate())<= 6
      

  7.   

    这样每行都要计算,然后再比较,会多一个操作
    如果在前面计算好,直接用between and 速度有优势