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

    本周:select * from table where datediff(week,C_CALLTIME,getdate())=0     --C_CALLTIME 为日期字段
    本月:select * from table where datediff(Month,C_CALLTIME,getdate())=0   --C_CALLTIME 为日期字段
    本季:select * from table where datediff(qq,C_CALLTIME,getdate())=0 

    求以下日期SQL:

    昨天 

    select convert(varchar(10),getdate() - 1,120)

    明天

    select convert(varchar(10),getdate() + 1,120)

    最近七天

    select * from tb where 时间字段 >= convert(varchar(10),getdate() - 7,120)

    随后七天

    select * from tb where 时间字段 <= convert(varchar(10),getdate() + 7,120) and 时间字段 >= 时间字段

    上月

    select * from tb where month(时间字段) = month(getdate()) - 1

    本月

    select * from tb where month(时间字段) = month(getdate())

    下月

    select * from tb where month(时间字段) = month(getdate()) + 1

    如果是在表中查詢:

    --昨天 

    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 * From TableName Where DateDiff(dd, GetDate(), DateTimCol) <= 7

    --上周

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

    --本周

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

    --下周

    Select * From TableName Where DateDiff(wk, GetDate(), DateTimCol ) = 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

    >>>更多  >>

  • 相关阅读:
    java1234初学maven
    解决maven创建web项目卡死在generator插件(转)
    maven下载速度慢的解决方法(转)
    git分支
    git基础
    oracle分析函数与over()(转)
    Oracle开窗函数 over()(转)
    Oracle计算时间函数(对时间的加减numtodsinterval、numtoyminterval) (转)
    selenium使用中遇到的问题
    selenium运行火狐报错FirefoxDriver : Unable to connect to host 127.0.0.1 on port 7055
  • 原文地址:https://www.cnblogs.com/shuai7boy/p/8426001.html
Copyright © 2011-2022 走看看