0

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

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

我没有工作:

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

有谁知道诀​​窍?

4

3 回答 3

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
于 2013-09-03T12:56:22.877 回答
0

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

请参阅:mysql:获取两个日期时间之间的记录计数

于 2013-09-03T12:53:32.257 回答
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' 
于 2013-09-03T13:04:45.153 回答