zoukankan      html  css  js  c++  java
  • Sql Server 查询指定范围(一周,一月,本周,本月等)内的数据

    select * from dbo.pf_Get_TargetData('','') where 1=1 and Style=N'温度' and datediff(day,datacreateon,getdate())<=7  一周  用week 是上一个整周的,不是从当前往后推的日期 年也是一样

    select * from dbo.pf_Get_TargetData('','') where 1=1 and Style=N'温度' and datediff(year,DataCreateOn,getdate()-1)=0  一年

     

    1.查询今日的所有数据

    select * from 表名 where datediff(day,字段名,getdate())=0

    2.查询昨日的所有数据

    select * from 表名 where datediff(day,字段名,getdate()-1)=0

    3.查询当天日期在一周年的数据

    selcet * from 表名 where datediff(week,字段名,getdate()-1)=0

    4.查询前30天的数据

    select * from 表名 where datediff(d,字段名,getdate())<=30

    5.查询上一个月的数据

    select * from 表名 where datediff(m,字段名,getdate())<=1

    6.查询当天的数据

    select * from 表名 where datediff(dd,字段名,getdate())=0

    7.查询24小时内的数据

    select * from 表名 where datediff(hh,字段名,getdate())

    8.查询本周的数据

    select * from 表名 where datediff(week,字段名,getdate())=0

    9.查询本月的数据

    select * from 表名 where datediff(month,字段名,getdate())=0

    10.查询本季的数据

    select * from 表名 where datediff(qq,字段名,getdate())=0

  • 相关阅读:
    window.fonts
    smpt authentification 配置
    如何从思维上应对
    中文字体 英文字体
    Path Breadcrumbs
    drupal commerce app
    做视频或者什么模块开发之类的
    分页符 箭头 难看
    theme wrapper 例子
    background position 稍微深入
  • 原文地址:https://www.cnblogs.com/zuochanzi/p/14062553.html
Copyright © 2011-2022 走看看