zoukankan      html  css  js  c++  java
  • SQL Server常用SQL集合

    ================================================

    1、SQL查询一年之内的数据记录

    select * from 表名 where  CreateDate<GETDATE() and
    
    CreateDate>DATEADD(yy, -1, GETDATE())

    2、--查询当天记录:

    select * from info where DateDiff(dd,datetime,getdate())=0 

    3、--查询24小时内的记录:

    select * from info where DateDiff(hh,datetime,getDate())<=24 

    5、--查询本周记录

    select * from info where datediff(week,datetime,getdate())=0

    6、--查询本月记录

    select * from info where datediff(month,datetime,getdate())=0

    --info为表名,datetime为数据库中的日期字段

    DATEDIFF 函数:

    语法:


    DATEDIFF ( datepart , startdate , enddate )

    SQL语句统计每天、每月、每年的 数据

    7、统计每年

    select year(ordertime) AS '',
    sum(Total) '销售合计'
    from order_list
    group by year(ordertime)

    8、统计每月

    select year(ordertime) '',
    month(ordertime) '',
    sum(Total) '销售合计'
    from order_list
    group by year(ordertime),
    month(ordertime)

    9、统计每日

    select year(ordertime) '',
    month(ordertime) '',
    day(ordertime) '',
    sum(Total) '销售合计'
    from order_list
    group by year(ordertime),
    month(ordertime),
    day(ordertime)

    另外也可以这样:

    select convert(char(8),ordertime,112) dt,
    sum(Total) '销售合计'
    from order_list
    group by convert(char(8),ordertime,112)

    10、每月(年、日)的记录条数

    select year(ordertime) '',
    month(ordertime) '',
    count(*) '销售记录'
    from order_list
    group by year(ordertime),
    month(ordertime)

    11、

    12、

    13、

    14、

    15、

    16、

     

    =================================================

  • 相关阅读:
    Go:获取命令行参数
    Go:文件操作
    Go:类型断言
    GO:interface
    Go:面向"对象"
    Go:工厂模式
    layui中流加载layui.flow
    js显示当前时间
    layui中的分页laypage
    layui中的多图上传
  • 原文地址:https://www.cnblogs.com/yuwentao/p/9802636.html
Copyright © 2011-2022 走看看