Sql Server中询问当天,近年来11日,本周,本月,近期3个月,本季度的数码的sql语句

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*

前不久四日:

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

近来30日:

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

本季度:

一月    select * from T_news WHERE (DATEPART(yy, addtime) =
DATEPART(yy, GETDATE())) AND (DATEPART(mm, addtime) = DATEPART(mm,
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(qq, addtime) =
DATEPART(qq, GETDATE()) and DATEPART(yy, addtime) = DATEPART(yy,
GETDATE())

本周:

澳门新萄京,在意:此时不能够用 datediff 差值为7,因为,datediff只代表间隔数

select * from T_news WHERE (DATEPART(yy, addtime) = DATEPART(yy,
GETDATE())) 
AND ((DATEPART(mm, addtime) = DATEPART(mm, GETDATE())) OR
(31-DATEPART(DD,addtime)+DATEPART(DD, GETDATE()))<=31)

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

发表评论

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

网站地图xml地图