sql语句根据日期查询,本周,本月,本年,今日相关统计

昨天
select * from tb where datediff(day, 时间字段 ,getdate()) = 1
今天
select * from tb where datediff(day, 时间字段 ,getdate()) = 0
本周
select * from tb where datediff(week, 时间字段 ,getdate()) = 0
上周
select * from tb where datediff(week, 时间字段 ,getdate()) = 1
下周
select * from tb where datediff(week, 时间字段 ,getdate()) = -1

上月
Select * From TableName Where DateDiff(month, 时间字段, GetDate()) = 1
本月
Select * From TableName Where DateDiff(month,时间字段, GetDate()) = 0
下月
Select * From TableName Where DateDiff(month, GetDate(), 时间字段) = -1
本年
Select * From TableName Where DateDiff(year, GetDate(), 时间字段 ) = 0

昨天:dateadd(day,-1,getdate())
明天:dateadd(day,1,getdate())
上月:month(dateadd(month, -1, getdate()))
本月:month(getdate())
下月:month(dateadd(month, 1, getdate()))

昨天 
Select * From TableName Where DateDiff(dd, DateTimCol, GetDate()) = 1
明天
Select * From TableName Where DateDiff(dd, GetDate(), DateTimCol) = -1
最近七天
Select * From TableName Where DateDiff(dd, DateTimCol, GetDate()) <= 7
随后七天

当前年
select 提出日期, datepart(year,getdate()) as 当前年 from 供方资料表
前一年
select 提出日期, datepart(year,getdate())-1 as 当前年 from 供方资料表
后一年
select 提出日期, datepart(year,getdate())+1 as 当前年 from 供方资料表

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值