永利酒店赌场SQLServer查询最近一天,三天,一周,一月,一季度方法

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)

 

永利酒店赌场SQLServer查询最近一天,三天,一周,一月,一季度方法。注意:此时不能用 datediff 差值为7,因为,datediff只表示间隔数

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 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())”;

当天:

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

最近一个月:

 

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

 

最近三天:

 

本月:

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

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

 

本周:

本季度:

网站地图xml地图