使用DATETIME mysql查询日期之间的时间范围 [英] Query Time range between Dates using DATETIME mysql

查看:146
本文介绍了使用DATETIME mysql查询日期之间的时间范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据库表,其中有这样的字段:

I have a database table that has fields as such :

TIME(Datetime)        Update_ID
2013-11-25 05:00:14     XC3
2013-11-25 06:00:13     XC4
2013-11-25 06:00:19     XC5
2013-12-25 23:00:14     XC6
2013-12-25 24:00:00     XC7

所以假设我想要了解更新的趋势,以了解一天中的哪一段时间有一个特定数量的更新,我最初想到的是这样做:

So assuming i want to find a trend on the updates to know which period of the day has the a particular number of updates, what i initially think of is doing something like this :

SELECT COUNT(TIME) FROM  table WHERE TIME between '06:00:00' and '12:00:00' 

但是这不起作用,因为我认为自从日期没有添加到时间之后,添加了一个默认的日期值(约在1970年左右)。如果我在查询中添加了开始和结束,我恐怕不会给我所需要的结果。

But this doesn't work because i think since the date is not added with the time, a default value for date is added(some date around 1970). If, i add the beginning and enddate in my query, i am afraid it won't give me the results i need.

推荐答案

使用

WHERE HOUR(TIME)...GROUP BY DAY(TIME) 

如果您有超过1天

这篇关于使用DATETIME mysql查询日期之间的时间范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆