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

    本周

    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(mm, DateTimCol, GetDate()) = 1

    --本月

    Select * From TableName Where DateDiff(mm, DateTimCol, GetDate()) = 0

    --下月

    Select * From TableName Where DateDiff(mm, GetDate(), DateTimCol ) = 1


    昨天: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 供方资料表

    生命不息,奋斗不止
  • 相关阅读:
    java处理高并发高负载类网站的优化方法
    谈谈Memcached与Redis
    php中const与define的使用区别 详解
    ecshop添加模板与库文件
    ECShop 2.5.1 的结构图及各文件相应功能介绍
    Uva10972(RevolC FaeLoN)
    交叉染色法判断二分图
    边双联通问题求解(构造边双连通图)POJ3352(Road Construction)
    POI1999(仓库管理员)
    ZOJ1311(Network)
  • 原文地址:https://www.cnblogs.com/Griffin/p/2576967.html
Copyright © 2011-2022 走看看