SQLServer查询近些日子一天,三日,一周,7月,一季度方式

近些年十六日:

一月    select * from T_news WHERE (DATEPART(yy, addtime) =
DATEPART(yy, GETDATE())) AND (DATEPART(mm, addtime) = DATEPART(mm,
GETDATE()))

select * from T_news where DATEPART(qq, addtime) = DATEPART(qq,
GETDATE()) and DATEPART(yy, addtime) = DATEPART(yy, GETDATE())

一周 澳门新萄京,select \ from T_news WHERE (DATEPART(wk, addtime) =
DATEPART(wk, GETDATE())) AND (DATEPART(yy, addtime) = DATEPART(yy,
GETDATE()))*

select * from T_news WHERE (DATEPART(wk, addtime) = DATEPART(wk,
GETDATE())) AND (DATEPART(yy, addtime) = DATEPART(yy, GETDATE()))

三天 select \ from T_news where
datediff(day,addtime,getdate())<= 2 and
datediff(day,addtime,getdate())>= 0*

本月:

在意:此时不能够用 datediff 差值为7,因为,datediff只表示间隔数

当天:

一天 select \ from T_news where
datediff(day,addtime,getdate())=0*

select * from T_news where datediff(day,addtime,getdate())<= 2 and
datediff(day,addtime,getdate())>= 0

一季度 select * from T_news where DATEPART(qq, addtime) =
DATEPART(qq, GETDATE()) and DATEPART(yy, addtime) = DATEPART(yy,
GETDATE())

只顾:此时无法用 datediff 差值为7,因为,datediff只表示间隔数

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图