zoukankan      html  css  js  c++  java
  • 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 供方资料表

  • 相关阅读:
    cereal:C++实现的开源序列化库
    随笔
    我们一起成长
    青岛近代历史和文化资料整理
    Codeforces Round #580 (Div. 2)-D. Shortest Cycle(思维建图+dfs找最小环)
    CodeForces
    PAT甲级1151(由前序和中序确定LCA)
    记录使用vs code两天的心得
    AcWing 285. 没有上司的舞会(树形dp入门)
    POJ-3255-Roadblocks(次短路的另一种求法)
  • 原文地址:https://www.cnblogs.com/shx1024/p/11931237.html
Copyright © 2011-2022 走看看