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())
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())
问题已经解决。还有个简单的问题。怎么查询最近一周的信息where在inner 的后面
datediff(dd,r.BeginTime,getdate()) between 1 and 7 datediff(dd,r.BeginTime,getdate()) between 0 and 7自己看哪个合适,或者自己更改日期范围.
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() --查询七天前到现在的数据
输出上个星期天到这个星期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
where r.BeginTime > dateadd(hh,-24,getdate()) 放到inner join on 后面。
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())
from Record as r
inner join Card as c
on r.CardID = c.ID
where r.BeginTime > dateadd(hh,-24,getdate())
from Record as r
inner join Card as c
on r.CardID = c.ID
where r.BeginTime > dateadd(hh,-24,getdate())
datediff(dd,r.BeginTime,getdate()) between 0 and 7自己看哪个合适,或者自己更改日期范围.
from Record as r
inner join Card as c
on r.CardID = c.ID
where r.BeginTime between dateadd(dd,-7,getdate()) and getdate()
--查询七天前到现在的数据
输出上个星期天到这个星期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
from Record as r
inner join Card as c
on r.CardID = c.ID
where datepart(wk,r.BeginTime) = datepart(wk,getdate())