I am attempting to select a row from the database based on a time value.
我试图根据时间值从数据库中选择一行。
My database contains a table of actions. These actions run ever x number of minutes. When the action is ran, the row is updated and it's last_run
column which is a TIMESTAMP
containing the value of NOW()
我的数据库包含一个操作表。这些操作可以运行x分钟。当该动作运行时,该行被更新,它的last_run列是一个包含NOW()值的TIMESTAMP
Here is a valid row in the database. As you can see from this row it was last run some days ago. It's set to run every 60 minutes.
这是数据库中的有效行。从这一行可以看出它是几天前的最后一次运行。它设置为每60分钟运行一次。
I use INTERVAL last_run + interval_minutes < NOW()
. So, the last run time, plus sixty minutes, would be less than the value of NOW()
if 60 minutes has passed.
我使用INTERVAL last_run + interval_minutes
The query I am trying to run is below:
我试图运行的查询如下:
SELECT
*
FROM
routine_actions
WHERE
routine_actions.routine_id = 12
AND
INTERVAL routine_actions.interval_minutes MINUTE + routine_actions.last_run < NOW()
GROUP BY routine_id
But, I'm getting no results. Any idea's what I could be doing wrong?
但是,我没有得到任何结果。任何想法都是我可能做错了什么?
1 个解决方案
#1
1
The query you're trying looks ok but in the first part of your question, the following
您正在尝试的查询看起来不错,但在您的问题的第一部分,以下内容
INTERVAL last_run + interval_minutes MINUTES < NOW()
should be
INTERVAL interval_minutes MINUTES + last_run < NOW()
#1
1
The query you're trying looks ok but in the first part of your question, the following
您正在尝试的查询看起来不错,但在您的问题的第一部分,以下内容
INTERVAL last_run + interval_minutes MINUTES < NOW()
should be
INTERVAL interval_minutes MINUTES + last_run < NOW()