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

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、

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

SQL Server常用SQL集合的更多相关文章

  1. SQL Server 常用SQL

    --查询所有表 select * from sysobjects where xtype='u' ORDER BY name ASC

  2. sql server 常用sql语句

    --删除约束 alter table productInfo drop constraint 约束名称 --删除列alter table productInfo drop column 列名 --添加 ...

  3. [SQL Server] 常用sql脚本

    1.添加表 GO IF NOT EXISTS(SELECT * FROM sys.tables WHERE name='table_name') BEGIN CREATE TABLE [dbo].[t ...

  4. sql server 常用的系统存储过程

      系统存储过程 说明 sp_databases 列出服务上的所有数据库 sp_helpdb 报告有关指定数据库或所有数据库的信息 sp_renamedb 更改数据库的名称 sp_tables 返回当 ...

  5. SQL Server中的集合运算: UNION, EXCEPT和INTERSECT

    SQL Server中的集合运算包括UNION(合并),EXCEPT(差集)和INTERSECT(相交)三种. 集合运算的基本使用 1.UNION(合并两个查询结果集,隐式DINSTINCT,删除重复 ...

  6. SQL SERVER常用语法记录

    用于记录SQL SERVER常用语法,以及内置函数. 以下语句包含: WITH 临时表语法 ROW_NUMBER()内置函数,我一般主要是用来分页.针对于查出来的所有数据做一个数字排序 分页的BETW ...

  7. SQL SERVER常用语法汇总

    阅读目录 一.SQL分类 二.基础语句 三.sql技巧 四.(MS SQL Server)SQL语句导入导出大全 回到目录 一.SQL分类 DDL—数据定义语言(CREATE,ALTER,DROP,D ...

  8. sql server常用性能计数器

    https://blog.csdn.net/kk185800961/article/details/52462913?utm_source=blogxgwz5 https://blog.csdn.ne ...

  9. SQL Server经典sql语句大全(转)

    一.基础1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备份数 ...

随机推荐

  1. LRU缓存淘汰算法

    什么是LRU算法? LRU是Least Recently Used的缩写,即最近最少使用,在有限的内容块中存储最近使用次数最多的数据,当内容块已满时,把最少使用的数据删除以便存储新的内容.

  2. MySQL修改时间函数 1.addDate(date , INTERVAL expr unit) 2.date_format(date,’%Y-%m-%d’) 3.str_to_date(date,’%Y-%m-%d’) 4.DATE_SUB(NOW(), INTERVAL 48 HOUR)

    MySQL修改时间函数: 1. addDate(date,INTERVAL expr unit)   interval 代表时间间隔 : SELECT NOW();           2018-06 ...

  3. URAL 1303 Minimal Coverage

    URAL 1303 思路: dp+贪心,然后记录路径 mx[i]表示从i开始最大可以到的位置 sufmx[i]表从1-i的某个位置开始最大可以到达的位置 比普通的贪心效率要高很多 代码: #inclu ...

  4. Codeforces 768B - Code For 1(分治思想)

    768B - Code For 1 思路:类似于线段树的区间查询. 代码: #include<bits/stdc++.h> using namespace std; #define ll ...

  5. 多年未写过java了

    java面试必须了解和记忆的知识点(linux,nginx,数据库之类的暂时不考虑了) java面试的115常见问题,这个博客还是不过的推荐一下吧 http://www.importnew.com/1 ...

  6. 一套C#语言的日志控制系统

    using System; public delegate void LogHandle(Object log); public class PlayerHandle { public static ...

  7. Java使用Log4记录日志

    我们在系统使用中,为了方便查找问题,因此需要记录操作的日志,而目前比较成熟稳定的程序日志记录方式就是Log4,本人也是菜鸟,然后再学习研究中就记录一下使用方式,以方便今后查阅,同时本文章参考了博客园: ...

  8. PHP函数总结 (七)

    <?php /** * 匿名函数(闭包函数): * php>=5.3 * 允许临时创建一个没有指定名称的函数,常作为回调函数参数的值 * * 闭包的另一个概念: * 在内部函数中可以使用外 ...

  9. bzoj4025: 二分图 lct

    题意:带增删边的查询二分图 题解:因为二分图肯定带奇环,lct维护,每次要加入一条边之前判断会不会构成环,如果会就把最先会删除的边删掉,然后如果是奇环就打个标记,然后把奇环数++,删除的时候,把标记删 ...

  10. OC 类对象和类加载

    //------------------------Persion类----------------------------// 1 #import "Person.h" @imp ...