--按mySql语法统计按周,月,季,年。income为合计的价格字段,createDate为交易时间。
select sum(income)as revenue,week(createDate) as week,month(createDate) as month, quarter(createDate)as quarter,year(createDate)as year from employee
where year(createDate) >= '' group by
week(createDate),month(createDate),quarter(createDate),year(createDate) --sqlserver2005语法统计按周,月,季,年。 --按日
--select sum(price),day([date]) from table_name where year([date]) =
'' group by day([date])
--按周quarter
select sum(price),datename(week,price_time) from ble_name where
year(price_time) = '' group by datename(week,price_time)
--按月
select sum(price),month(price_time) from ble_name where year(price_time)
= '' group by month(price_time)
--按季
select sum(price),datename(quarter,price_time) from ble_name where
year(price_time) = '' group by datename(quarter,price_time) --按年
select sum(price),year(price_time) from ble_name where
year(price_time) >= '' group by year(price_time)

用sql语句按周、按月、按季、按年统计的更多相关文章

  1. 数据库:sql语句分别按日,按周,按月,按季统计金额

    如: 表:consume_record 字段:consume (money类型) date (datetime类型) 请问怎么写四条sql语句分别按日,按周,按月,按季统计消费总量. 如:1月 120 ...

  2. SQL SERVER 月、季、年统计与常用查询语句汇总

    一.SQL SERVER 月.季.年统计查询 --本天 SELECT *FROM dbo.TableName WHERE DATEDIFF(DAY,TimeField,getdate())= 0; - ...

  3. SQLServer用sql语句怎么返回一个月所有的天数

    可用如下sql语句: select convert(varchar(10),dateadd(DAY,t2.number,t1.day),120) day from (select '2015-07'+ ...

  4. 用sql语句按周、按月、按季、按年统

    原文地址:http://hi.baidu.com/%BD%F0%D3%F1kl_y/blog/item/1c368ffba9388476024f5645.html --按mySql语法统计按周,月,季 ...

  5. sql 指定时间 所在的周、月、季、年

    DECLARE @TodayDateTime DATETIMEDECLARE @strToday NVARCHAR(19) DECLARE @TodayBeginDateTime DATETIMEDE ...

  6. ORACLE取周、月、季、年的開始时间和结束时间

     1           取周的開始时间和结束时间 取周的開始时间.以星期一为開始. SQL>SELECT TRUNC(TO_DATE('2013-11-25 10:31:11','YYYY ...

  7. 转载:SQL按照日、周、月、年统计数据的方法

    转载源:http://www.jb51.net/article/42613.htm SQL按照日.周.月.季度.年统计数据的方法 方式一: --按日 select sum(consume),day([ ...

  8. 几条复杂的SQL语句

    表结构:CREATE TABLE [dbo].[Exam](    [S_date] [datetime] NOT NULL,    [Order_Id] [varchar](50) NOT NULL ...

  9. 两种方式:mysql查看正在执行的sql语句

    mysql查看正在执行的sql语句 2015年08月21日 17:32:59 阅读数:15398   有2个方法: 1.使用processlist,但是有个弊端,就是只能查看正在执行的sql语句,对应 ...

随机推荐

  1. c++中字符串的截取:

    c++中字符串的截取: string 类提供字符串处理函数,利用这些函数,程序员可以在字符串内查找字符,提取连续字符序列(称为子串),以及在字符串中删除和添加.我们将介绍一些主要函数. 1.函数fin ...

  2. NULL 与 ""

    char *str1 = NULL; //str1为空 char *str2 = ""; //str2为一个空字符串 NULL没有分配空间,""分配了空间.

  3. 开源库ActiveAndroid + gson使用

    ActiceAndroid的简介 ActiveAndroid是一个活跃的记录风格的ORM(对象关系映射)库.ActiveAndroid可以让您保存和检索的SQLite数据库记录而没有写一个SQL语句. ...

  4. matlab基本语法和运算基础

    转载自:http://blog.csdn.net/robertcalm/article/details/51582253 matlab语法比较随意,但正如其全名 matrix &laborat ...

  5. 滴水穿石 C#中多线程 委托的使用

    什么是多线程?我们在建立以个C#项目时,往往会在Form1上添加控件,然后写代码,初 学者都是在重复这个过程,其实这个过程是单线程的,可以理解为只有“main”主线程,有 的时候往往需要同时测量多个东 ...

  6. http://lorempixel.com/ 可以快速产生假图

    http://lorempixel.com/可以快速产生假图

  7. 飘逸的python - @staticmethod和@classmethod的作用与区别

    一般来说,要使用某个类的方法,需要先实例化一个对象再调用方法. 而使用@staticmethod或@classmethod,就可以不需要实例化,直接类名.方法名()来调用. 这有利于组织代码,把某些应 ...

  8. Java8 使用 stream().sorted()对List集合进行排序

    集合对像定义 集合对象以学生类(StudentInfo)为例,有学生的基本信息,包括:姓名,性别,年龄,身高,生日几项. 使用stream().sorted()进行排序,需要该类实现 Comparab ...

  9. validate验证注册表单

    点击预览; <%@ page language="java" contentType="text/html; charset=UTF-8" pageEnc ...

  10. 如何简单的理解TDD与DDT

    TDD:TEST-DRIVEN Development 测试驱动开发究竟是什么意思?如何理解测试驱动开发? 举个红绿条简单的例子: 1.编写测试代码 2.编译运行测试代码,肯定会失败,因为实现代码还没 ...