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、

     

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

  • 相关阅读:
    IEXPRESS
    .NET protector
    aspnet_compiler
    Ubuntu 添加新用户并制定目录和shell,并配置为root组用户|sudoer 修改
    键盘驱动的原理
    几个常用的宏:likely和unlikely __raw_writel
    android 静音与振动
    Ubuntu 添加新用户并制定目录和shell,并配置为root组用户|sudoer 修改
    Linux输入子系统
    Android input device request_irq() 的 注册中断服务
  • 原文地址:https://www.cnblogs.com/yuwentao/p/9802636.html
Copyright © 2011-2022 走看看