试图在time1和time2之间计算mysql数据

时间:2013-09-03 12:50:33

标签: mysql datetime time between

我有一个数据库表'email_log',其中包含以下信息: 用户,主题和打开(作为日期时间)

我需要的是一个新查询,我可以从中查看有多少行包含08:0009:00之间的“已打开”列。

我所做的不起作用:

SELECT count(*) as count FROM email_log WHERE opened BETWEEN '00:08:00' AND '00:09:00';

有人知道这个伎俩吗?

3 个答案:

答案 0 :(得分:0)

您可能需要包含datetime的整个格式 - 因为它既有日期又有时间。

请参阅:mysql: get record count between two date-time

答案 1 :(得分:0)

尝试

SELECT count(*) as count FROM email_log WHERE 
opened BETWEEN STR_TO_DATE('5/15/2012', '%c/%e/%Y') 
AND STR_TO_DATE('5/15/2012', '%c/%e/%Y'); // date only

SELECT count(*) as count FROM email_log WHERE 
opened BETWEEN STR_TO_DATE('8:06:26 AM', '%r') 
AND STR_TO_DATE('8:06:26 AM', '%r'); // time only

答案 2 :(得分:0)

试试这个

SELECT COUNT(*) AS COUNT 
FROM email_log 
WHERE  DATE_FORMAT(opened,"%H:%i:%S")  > '00:08:00' AND  DATE_FORMAT(opened,"%H:%i:%S")  < '00:09:00'