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

    获取周数据

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

     获取月数据

    本月
    select * from table1 where datediff(mm,时间字段,getdate()) = 0
    上月 select * from table1 where datediff(mm,时间字段,getdate()) = 1
    下月 select * from table1 where datediff(mm,时间字段,getdate()) = -1
    昨天:
    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
    
  • 相关阅读:
    Pagodas
    Bazinga
    取石子问题
    Sudoku Killer(hdu 1426 数独)
    欧拉函数
    CCPC Ancient Go
    ZZNU 1992: 情人节的尴尬
    fzu Problem 2128 最长子串(KMP + strstr 经典好题)
    POJ
    HDU
  • 原文地址:https://www.cnblogs.com/sntetwt/p/12205527.html
Copyright © 2011-2022 走看看