[英]MySQL date interval on select
i've made this SQL code : 我做了这个SQL代码:
CREATE TABLE `logs` (
`id_log` INT(11) NOT NULL AUTO_INCREMENT,
`data_log` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id_log`),
)
i made it to Insert a record when my server goes down,but i would like to make some check if it wasn't Inserted the same record 10 minutes before. 我在服务器故障时让它插入一条记录,但是我想做一下检查,如果它不是在10分钟前插入相同的记录。
So i was looking for some SELECT that shows only records from NOW() to 10 minutes before. 所以我一直在寻找一些仅显示从NOW()到10分钟之前的记录的SELECT 。
这将返回最近十分钟写入日志的记录数:
SELECT Count(*) as count_in_last_10 FROM logs WHERE data_log BETWEEN DATE(NOW()-INTERVAL 10 MINUTE) AND NOW()
You're looking for INTERVAL # [UNIT]
, there's various ways to use it -- http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html : 您正在寻找
INTERVAL # [UNIT]
,有多种使用方式-http : //dev.mysql.com/doc/refman/5.5/zh-CN/date-and-time-functions.html :
SELECT count(*)
FROM logs
WHERE data_log > NOW() - INTERVAL 10 MINUTE;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.