SELECT DATE_FORMAT( deteline, "%Y-%m-%d %H" ) , COUNT( * )

FROM test

GROUP BY DATE_FORMAT( deteline, "%Y-%m-%d %H" )

查询某天:

deteline, "%Y-%m-%d"

某时:

deteline, "%Y-%m-%d %H"

依次类推。

其实就是对dateline进行处理,然后再对处理后的数据分组

ex:统计每小时创建的个数

 SELECT DATE_FORMAT( create_time, "%Y-%m-%d %H" ) as time , COUNT( * ) as count FROM pdca GROUP BY DATE_FORMAT( create_time, "%Y-%m-%d %H" )

Ex2:比较时间

     <select id="queryByStatusAndTime" parameterType="map" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from pdca
<where> begin_time is not null and end_time is not null <if test="userId != null and userId != '' ">
and user_id=#{userId}
</if> <if test="status != null">
and status in
<foreach collection="status" item="s" open="(" separator="," close=")">
#{s}
</foreach>
</if> <if test="finishedTime != null and finishedTime != ''">
and date_format(finished_time, '%Y-%m')=date_format(#{finishedTime}, '%Y-%m')
</if> <if test="endTime != null and endtime != ''">
and date_format(end_time, '%Y-%m-%d')=date_format(#{endTime}, '%Y-%m-%d')
</if> <if test="endTimeLt != null and endtimeLt != ''">
and end_time &lt; #{endTimeLt}
</if> <if test="endTimeGt != null and endtimeGt != ''">
and end_time &gt; #{endTimeGt}
</if> <if test="beginTime != null and beginTime != ''">
and date_format(begin_time, '%Y-%m-%d')=date_format(#{beginTime}, '%Y-%m-%d')
</if> <if test="completion != null">
and completion=#{completion}
</if>
</where>
</select>

mysql时间字符串按年/月/天/时分组查询 -- date_format的更多相关文章

  1. mysql时间字符串按年/月/天/时分组查询

    SELECT DATE_FORMAT( deteline, "%Y-%m-%d %H" ) , COUNT( * ) FROM test GROUP BY DATE_FORMAT( ...

  2. mysql数据库,当数据类型是float时,查询居然查询不出数据来

    mysql数据库,当数据类型是float时,查询居然查询不出数据来,类似如下: 以后mysql数据库不用float类型,而double类型可以查得出来.

  3. mysql系列九、mysql语句执行过程及运行原理(分组查询和关联查询原理)

    一.背景介绍 了解一个sql语句的执行过程,了解一部分都做了什么,更有利于对sql进行优化,因为你知道它的每一个连接.where.分组.子查询是怎么运行的,都干了什么,才会知道怎么写是不合理的. 大致 ...

  4. WeUI移动页面实现时间选择器(年-月-日-时-分)

    在做微信公众号的时候,使用的WeUI样式,有一个需求是用户选择一个预约时间,需要年月日并精确到小时和分钟. 但是WeUI的picker组件不支持直接显示5列,根据WeUI.js作者的建议,是将日期和时 ...

  5. js将当前时间格式化为年-月-日 时:分:秒

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. MySQL时间类型datetime、bigint及timestamp的查询效率

    前期数据准备 通过程序往数据库插入 50w 数据 数据表: CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `time_dat ...

  7. MySQL时间分组查询

    表TESTER 字段:id -- INT    date  -- TIMESTAMP 1.如何按年.月.日分组查询? select DATE_FORMAT(date,'%Y-%m-%d') time, ...

  8. Java8获取当前时间、新的时间日期类如Java8的LocalDate与Date相互转换、ZonedDateTime等常用操作包含多个使用示例、Java8时区ZoneId的使用方法、Java8时间字符串解析成类

     下面将依次介绍 Date转Java8时间类操作 ,Java8时间类LocalDate常用操作(如获得当前日期,两个日期相差多少天,下个星期的日期,下个月第一天等) 解析不同时间字符串成对应的Java ...

  9. mysql时间操作(时间差和时间戳和时间字符串的互转)

    mysql时间操作(时间差和时间戳和时间字符串的互转) 两个时间差: MySQL datediff(date1,date2):两个日期相减 date1 - date2,返回天数. select dat ...

随机推荐

  1. PHP 7 安装 Memcache 和 Memcached 总结

    Memcache 与 Memcached 的区别 Memcached 是 Memcache 的升级版,优化了 Memcache,并增加了一些操作方法.所以现在基本都是用最近版本的. PHP 7 下安装 ...

  2. D3 API总览

    D3图形库API参考 https://github.com/d3/d3/wiki/API--%E4%B8%AD%E6%96%87%E6%89%8B%E5%86%8C d3 官网 API https:/ ...

  3. uploadify的碎碎念 upload

    uploadify是一个jquery插件,用来实现文件上传的功能. 20160724 看起来感觉挺麻烦的 一般会买一个html5版的. html <input id="custom_f ...

  4. spring mvc配置ObjectMapper忽略无法识别的字段,以及一些博客推荐

    通过Spring的MethodInvokingFactoryBean类实现的调用configure方法,此方法返回调用该方法的本身实例. 配置完毕后,可以在spring mvc的消息处理器中使用,为了 ...

  5. Install Nginx on CentOS 7

    To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with ...

  6. 守护进程与Supervisor

    博客链接:http://www.cnblogs.com/zhenghongxin/p/8676565.html 消息队列处理后台任务带来的问题 在系统稍微大些的时候,我们经常会用到消息队列(实现的方式 ...

  7. iOS method swizz

    1: 防止按钮在一定时间内重复响应默认1秒 // // UIButton+AvoidDoubleClick.h // 51WaywardShop // // Created by jisa on 20 ...

  8. django项目中使用项目环境制作脚本 通过终端命令运行脚本文件

    在实际的django项目开发中,有时候需要制作一些脚本文件对项目数据进行处理,然后通过终端命令运行脚本. 完整的实现流程如下: 1.在一个应用目录下(app, 必须是在应用目录下,可以专门创建一个应用 ...

  9. Django(图书管理系统1)

    day63 内容回顾     1. 单表的增删改查         1. 删和改             1. GET请求 URL传值                 1. 格式            ...

  10. 浅谈对MVC的认识

    MVC是model(模型),view(视图),Controller(控制)的缩写. 模型层负责提供数据,和数据库相关的操作都交给模型层处理: 视图层提供交互的界面,其输出数据: 控制层负责接收各种请求 ...