select count(*) 
from SupplementDemand 
where and datediff(hh,CreateTime,getdate())<1
我想查的是与当前时间相差1小时之内的数据,请问我这样写对吗?

解决方案 »

  1.   

    select count(*) 
    from SupplementDemand 
    where and datediff(hh,CreateTime,getdate())<1这个去掉就行!
      

  2.   

    select count(*) 
    from SupplementDemand 
    where datediff(hh,CreateTime,getdate())<1
    这样就可以了
      

  3.   


    select count(*) 
    from SupplementDemand 
    where abs(datediff(hh,CreateTime,getdate()))<1
      

  4.   

    where 不能和 and 放一起
      

  5.   


    select count(*) 
    from SupplementDemand 
    where datediff(mi,CreateTime,getdate()) between 0 and 60
    当CreateTime大于getdate()时,返回的是负数
    若要求小于当前时间,且与当前时间相差一小时,则用如上sql,
    若只要求与当前时间相差一小时,则为between -60 and 60
      

  6.   

    select count(*) 
    from SupplementDemand 
    where datediff(hh,CreateTime,getdate())<1
      

  7.   

    select count(*) 
    from SupplementDemand 
    where abs(datediff(hh,CreateTime,getdate()))<1这个