[英]Why does this MySQL query return 0 results
我想在过去5分钟内获得所有记录,但它什么都没有返回..
SELECT * FROM (`user_actions`) WHERE `IP` = '127.0.0.1' AND `type` = 'Failed Login' AND date =DATE_SUB(NOW(), INTERVAL 5 MINUTE)
It's returning nothing because there no results for what you're asking for.... a date of exactly 5 minutes ago. 它没有返回任何东西,因为你要求的东西没有结果...... 恰好是 5分钟之前的日期。
You should not use the =
operator for your DATE
, you should be using inequalities. 你不应该在你的
DATE
使用=
运算符,你应该使用不等式。
That is, you want the date greater than 5-minutes-ago 也就是说,您希望日期大于5分钟前
It should be date >
not date =
, which would only match rows exactly equal to the time 5 minutes ago. 它应该是
date >
not date =
,它只匹配完全等于5分钟前的时间的行。
As an example, if it is currently 12:30PM, to find the rows that are within the last 5 minutes, you want all those with a time greater than 12:25PM. 例如,如果当前是下午12:30,要查找最近5分钟内的行,您需要所有时间大于12:25 PM的行。 Querying only for rows with a time equal to 12:25PM won't give you those recorded at 12:26PM, 12:27PM, etc.
仅查询时间等于12:25 PM的行将不会给您在下午12:26,下午12:27等记录的行。
SELECT * FROM user_actions WHERE IP = '127.0.0.1' AND type = 'Failed Login' AND date > DATE_SUB(NOW(), INTERVAL 5 MINUTE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.