select c.UserName as 用户姓名
from Record as r
where r.BeginTime > dateadd(hh,-24,getdate()) 
inner join Card as c
on r.CardID = c.ID

解决方案 »

  1.   

    select c.UserName as 用户姓名
    from Record as r
    inner join Card as c
    on r.CardID = c.ID
    where r.BeginTime > dateadd(hh,-24,getdate())  
      

  2.   

    select c.UserName as 用户姓名
    from Record as r
    inner join Card as c
    on r.CardID = c.ID
    where r.BeginTime > dateadd(hh,-24,getdate())  
      

  3.   

    问题已经解决。还有个简单的问题。怎么查询最近一周的信息where在inner 的后面
      

  4.   

    datediff(dd,r.BeginTime,getdate()) between 1 and 7
    datediff(dd,r.BeginTime,getdate()) between 0 and 7自己看哪个合适,或者自己更改日期范围.
      

  5.   

    select c.UserName as 用户姓名
    from Record as r
    inner join Card as c
    on r.CardID = c.ID
    where r.BeginTime between dateadd(dd,-7,getdate()) and getdate() 
    --查询七天前到现在的数据
      

  6.   

    datediff(dd,dateadd(dd,7,begintime),getdate())=0
      

  7.   

    不是啦。。比如今天星期3,输出上个星期天到这个星期3的信息。。(或星期一到星期3)不要用到declare和流程函数
      

  8.   


    输出上个星期天到这个星期3的信息
    datediff(week,r.BeginTime,getdate()) between 0 and 1DATEDIFF
    返回跨两个指定日期的日期和时间边界数。 语法
    DATEDIFF ( datepart , startdate , enddate ) 参数
    datepart是规定了应在日期的哪一部分计算差额的参数。下表列出了 Microsoft® SQL Server™ 识别的日期部分和缩写。日期部分 缩写 
    year yy, yyyy 
    quarter qq, q 
    Month mm, m 
    dayofyear dy, y 
    Day dd, d 
    Week wk, ww 
    Hour hh 
    minute mi, n 
    second ss, s 
    millisecond ms 
      

  9.   

    where r.BeginTime > dateadd(hh,-24,getdate())  放到inner join on 后面。
     
      

  10.   

    select c.UserName as 用户姓名
    from Record as r
    inner join Card as c
    on r.CardID = c.ID
    where datepart(wk,r.BeginTime) = datepart(wk,getdate())