SQL: How do I query based on a dynamic date calculation?
<p>I have a table, <code>foos</code> that has a <code>last_checked_at</code> datetime field and a <code>checking_inverval</code> integer field.</p>

<p>I want to query all <code>foos</code> that haven't been checked since the checking interval. I've tried variations on the following:</p>

<pre><code>SELECT `foos`.* FROM `foos`
  WHERE (`foos.checking_interval` &lt; TIMESTAMPDIFF(SECOND, `foos.last_checked_at`, NOW())
</code></pre>

<p>But I have yet to have any success. Or maybe I'm barking down the wrong tree altogether, and should just have another column that has the calculated datetime and let my application handle setting that date.</p>

<p>Thanks</p>