zoukankan      html  css  js  c++  java
  • Sqlserver语句获取本周、上一周、本月数据

    sql语句获取本周、上一周、本月数据

    获取周数据

    1 本周
    2 select * from table1 where datediff(week,时间字段,getdate()) = 0
    3 上周
    4 select * from table1 where datediff(week,时间字段,getdate()) = 1
    5 下周
    6 select * from table1 where datediff(week,时间字段,getdate()) = -1

    获取月数据

    1 本月
    2 select * from table1 where datediff(mm,时间字段,getdate()) = 0
    3 上月
    4 select * from table1 where datediff(mm,时间字段,getdate()) = 1
    5 下月
    6 select * from table1 where datediff(mm,时间字段,getdate()) = -1

    昨天:

    dateadd(day,-1,getdate())

    明天:

    dateadd(day,1,getdate())

    上月:

    month(dateadd(month,-1,getdate()))

    本月:

    month(getdate())

    下月:

    month(dateadd(month,1,getdate()))

    昨天:

    select * from table1 where datediff(dd,时间字段,getdate()) = 1

    明天:

    select * from table1 where datediff(dd,getdate(),时间字段) = -1

    最近七天:

    select * from table1 where datediff(dd,时间字段,getdate()) <= 7

    当前年:

    select 提出日期,datepart(year,getdate()) as 当前年 from table1

    前一年:

    select 提出日期,datepart(year,getdate()) -1 as 当前年 from table1

    后一年:

    select 提出日期,datepart(year,getdate()) +1 as 当前年 from table1

     

  • 相关阅读:
    模块和包——Python
    异常——Python
    单例——Python
    类属性和类方法——Python
    继承和多态——Python
    私有属性和私有方法——Python
    面向对象封装案例——Python
    面相对象基础语法——Python
    类、接口作为成员变量类型——Java
    内部类的概念和分类——Java
  • 原文地址:https://www.cnblogs.com/Scholars/p/8919600.html
Copyright © 2011-2022 走看看