mysql时间字符串按年/月/天/时分组查询 -- date_format
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 < #{endTimeLt}
</if> <if test="endTimeGt != null and endtimeGt != ''">
and end_time > #{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的更多相关文章
- mysql时间字符串按年/月/天/时分组查询
SELECT DATE_FORMAT( deteline, "%Y-%m-%d %H" ) , COUNT( * ) FROM test GROUP BY DATE_FORMAT( ...
- mysql数据库,当数据类型是float时,查询居然查询不出数据来
mysql数据库,当数据类型是float时,查询居然查询不出数据来,类似如下: 以后mysql数据库不用float类型,而double类型可以查得出来.
- mysql系列九、mysql语句执行过程及运行原理(分组查询和关联查询原理)
一.背景介绍 了解一个sql语句的执行过程,了解一部分都做了什么,更有利于对sql进行优化,因为你知道它的每一个连接.where.分组.子查询是怎么运行的,都干了什么,才会知道怎么写是不合理的. 大致 ...
- WeUI移动页面实现时间选择器(年-月-日-时-分)
在做微信公众号的时候,使用的WeUI样式,有一个需求是用户选择一个预约时间,需要年月日并精确到小时和分钟. 但是WeUI的picker组件不支持直接显示5列,根据WeUI.js作者的建议,是将日期和时 ...
- js将当前时间格式化为年-月-日 时:分:秒
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- MySQL时间类型datetime、bigint及timestamp的查询效率
前期数据准备 通过程序往数据库插入 50w 数据 数据表: CREATE TABLE `users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `time_dat ...
- MySQL时间分组查询
表TESTER 字段:id -- INT date -- TIMESTAMP 1.如何按年.月.日分组查询? select DATE_FORMAT(date,'%Y-%m-%d') time, ...
- Java8获取当前时间、新的时间日期类如Java8的LocalDate与Date相互转换、ZonedDateTime等常用操作包含多个使用示例、Java8时区ZoneId的使用方法、Java8时间字符串解析成类
下面将依次介绍 Date转Java8时间类操作 ,Java8时间类LocalDate常用操作(如获得当前日期,两个日期相差多少天,下个星期的日期,下个月第一天等) 解析不同时间字符串成对应的Java ...
- mysql时间操作(时间差和时间戳和时间字符串的互转)
mysql时间操作(时间差和时间戳和时间字符串的互转) 两个时间差: MySQL datediff(date1,date2):两个日期相减 date1 - date2,返回天数. select dat ...
随机推荐
- [label][翻译][JavaScript]如何使用JavaScript操纵radio和check boxes
Radio 和 check boxes是form表单中的一部分,允许用户通过鼠标简单点击就可以选择.当与<textarea>元素的一般JavaScript操纵相比较,这些表单控件(form ...
- Bitcoin
看李笑来老师的2013演讲——Bitcoin is not virtual currency,it is a real world. 1.由于bitcoin的算法中进行有上限量的发布,所以这是不会出现 ...
- Linux服务器目录空间不足解决措施
一般情况下工作环境中我们的服务或数据库文件都会存储在一个单独挂载的分区中,一般占空间比较大的大多就是服务的运行日志以及数据库文件,当我们分区的可用空间不足时就需要我们对分区进行扩容,或者找其它方法 ...
- 在微信开发中如果WeixinJSBridge.call('closeWindow');关闭窗口无效!
原因是,成功后页面跳转到普通页面.必须在前面加上 parent.WeixinJSBridge.call('closeWindow'); 这样才行.如果是使用了iframe页面,这样也可以关闭网页,回到 ...
- 国际化SEO优化的最佳实践
作者:Kristopher Jones 翻译 :吴祺深 欢迎访问网易云社区,了解更多网易技术产品运营经验. 让我们来说一下hreflang属性.如果你还没有关掉这个页面,那么你已经完成了这个教程最重要 ...
- 第三章 CopyOnWriteArrayList源码解析
注:在看这篇文章之前,如果对ArrayList底层不清楚的话,建议先去看看ArrayList源码解析. http://www.cnblogs.com/java-zhao/p/5102342.html ...
- disruptor调优方法
翻译自disruptor在github上的文档,https://github.com/LMAX-Exchange/disruptor/wiki/Getting-Started Basic Tuning ...
- Android代码编译出现的错误
一.decoupled apps failed 解耦应用程序失败 2.每次编译时候一定先扩充内存 export JACK_SERVER_VM_ARGUMENTS="-Dfile.encod ...
- (2019)OCP 12c 062考试题库出现大量新题-4
4.Which four are true about creating and running a remote database scheduler jobs? A) A credential i ...
- C++中new申请动态数组
C++中数组分为静态数组和动态数组,静态数组必须确定数组的大小,不然编译错误:而动态数组大小可以不必固定,用多少申请多少.静态数组类于与我们去餐馆吃饭,餐馆会把菜做好.而动态数组类似于我们自己买菜做饭 ...