我有一个数据库表'email_log'
,其中包含以下信息:用户、主题和打开(作为日期时间)
我需要的是一个新查询,从中我可以看到有多少行包含在08:00
和之间“打开”的列09:00
。
我没有工作:
SELECT count(*) as count FROM email_log WHERE opened BETWEEN '00:08:00' AND '00:09:00';
有谁知道诀窍?
尝试
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
您可能需要包含datetime
- 的整个格式,因为它既有日期又有时间。
尝试这个
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'