按年汇总,统计:

select sum(mymoney) as totalmoney, count(*) as sheets from mytable group by date_format(col, '%Y');

按月汇总,统计:

select sum(mymoney) as totalmoney, count(*) as sheets from mytable group by date_format(col, '%Y-%m');

按季度汇总,统计:

select sum(mymoney) as totalmoney,count(*) as sheets from mytable group by concat(date_format(col, '%Y'),FLOOR((date_format(col, '%m')+2)/3));

select sum(mymoney) as totalmoney,count(*) as sheets from mytable group by concat(date_format(col, '%Y'),FLOOR((date_format(col, '%m')+2)/3));

按小时:

select sum(mymoney) as totalmoney,count(*) as sheets from mytable group by date_format(col, '%Y-%m-%d %H ');

查询 本年度的数据:

SELECT * FROM mytable WHERE year(FROM_UNIXTIME(my_time)) = year(curdate())

查询数据附带季度数:

SELECT id, quarter(FROM_UNIXTIME(my_time)) FROM mytable;

查询 本季度的数据:

SELECT * FROM mytable WHERE quarter(FROM_UNIXTIME(my_time)) = quarter(curdate());

本月统计:

select * from mytable where month(my_time1) = month(curdate()) and year(my_time2) = year(curdate())

本周统计:

select * from mytable where month(my_time1) = month(curdate()) and week(my_time2) = week(curdate())

N天内记录:

WHERE TO_DAYS(NOW())-TO_DAYS(时间字段)<=N

本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2012-11/74145.htm

mysql 按时间段统计(年,季度,月,天,时)的更多相关文章

  1. MySQL按天,按周,按月,按时间段统计【转载】

    自己做过MySQL按天,按周,按月,按时间段统计,但是不怎么满意,后来找到这位大神的博客,转载一下,谢谢这位博主的分享 知识点:DATE_FORMAT 使用示例 select DATE_FORMAT( ...

  2. PHP date()获取某时间段以周、月、季度为粒度的时间段数组

    date()函数: PHP date()  参考:https://www.hi-docs.com/php/date.html Linux date()参考:http://www.cnblogs.com ...

  3. Mysql 查询天、周,月,季度、年的数据

    Mysql 查询天.周,月,季度.年的数据 今天 select * from 表名 where to_days(时间字段名) = to_days(now()); 昨天 SELECT * FROM 表名 ...

  4. MySql查询时间段的方法(转)

    http://www.jb51.net/article/58668.htm 本文实例讲述了MySql查询时间段的方法.分享给大家供大家参考.具体方法如下: MySql查询时间段的方法未必人人都会,下面 ...

  5. MySql查询时间段的方法

    本文实例讲述了MySql查询时间段的方法.分享给大家供大家参考.具体方法如下: MySql查询时间段的方法未必人人都会,下面为您介绍两种MySql查询时间段的方法,供大家参考. MySql的时间字段有 ...

  6. Mysql按时间段分组查询

    Mysql按时间段分组查询来统计会员的个数,mysql个数 Mysql按时间段分组查询来统计会员的个数,mysql个数 1.使用case when方法(不建议使用)- 代码如下 复制代码SELECT ...

  7. MySQL按周统计 WEEK 实例

    MySQL按周统计每周数据总和,用到了WEEK,subdate,date_format,date_sub,date_add函数. WEEK() 查看给定日期周数,语法:WEEK(date, mode) ...

  8. Java统计用户年/月/周/日网站访问量

    一:准备工作,引入相关依赖: 二:运行效果图: 下一次访问 三:具体代码如下  (1):CountObjectInfo.java package cn.csrc.base.count; import ...

  9. MySQL InnoDB配置统计信息

    MySQL InnoDB配置统计信息 1. 配置持久化(Persistent)统计信息参数 1.1 配置自动触发更新统计信息参数 1.2 配置每张表的统计参数 1.3 配置InnoDB优化器统计信息的 ...

随机推荐

  1. wini -- FileSubmitByFTP

    // winFtpPutFiles.cpp : Defines the entry point for the console application.// #include "stdafx ...

  2. 关于imagic拼接透明背景图片的问题

    目标: 为了做图片水印,需要水平拼接多个logo和文字... 之前用过imagick,所以继续使用. 第一个版本:实现了图片和文字的拼接,代码如下: package main import ( &qu ...

  3. sublime插件@sublimelinter安装使用

    sublimelinter插件是一款sublime编辑器的代码校验插件,支持多种语言,对于前端来说主要包含css和js校验. 要是用这款插件 1)安装node,然后在全局安装jshint(npm in ...

  4. ASI 与 AFN

    HTTP终结者.功能十分强大. 基于底层的CFNetwork框架,运行效率很高. 可惜

  5. [修改后]html+css 做成一个可浏览的表格

    现在表格内容需要显示的要求如下: 1, 表格很大,界面放不小,需要放到div中. 2, 在div中可以用scroll滑动查看. 3, td中的内容保持在一行中. 4, 可以点击tr,然后可以选中并了解 ...

  6. MySQL 性能优化的最佳20多条经验分享

    当我们去设计数据库表结构,对操作数据库时(尤其是查表时的SQL语句),我们都需要注意数据操作的性能.这里,我们不会讲过多的SQL语句的优化,而只是针对MySQL这一Web应用最多的数据库.希望下面的这 ...

  7. Hadoop2.6.0的FileInputFormat的任务切分原理分析(即如何控制FileInputFormat的map任务数量)

    前言 首先确保已经搭建好Hadoop集群环境,可以参考<Linux下Hadoop集群环境的搭建>一文的内容.我在测试mapreduce任务时,发现相比于使用Job.setNumReduce ...

  8. Could not create the view: An unexpected exception was thrown 【转】

    转:http://blog.csdn.net/shuangzixing520/article/details/35225105 今天打开Myeclipse10的时候,发现server窗口出现一堆问题, ...

  9. second class

    nothing no very good. 1.look at shuruo.html,after display:inline-block; li's width as the content; S ...

  10. LeetCode(97) Interleaving String

    题目 Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: ...