菜单

Sql Server中询问当天,方今八天,本周,本月,近日一个月,本季度的数额的sql语句

2019年2月3日 - sqlite

近年来三天:

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

本月:

当天 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(wk, addtime) = DATEPART(wk,
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()))

本季度 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())=0

如今四日 select \ from T_news where
datediff(day,addtime,getdate())<= 2 and
datediff(day,addtime,getdate())>= 0*

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)

新近一个月:

当天:

本季度:

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

相关文章

发表评论

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

网站地图xml地图