title: MySQL: select last full 5 minute interval
body: <p>I want to select from my table the last full 5 minute interval.</p>
  
  <p>Example:</p>
  
  <ul>
  <li>Time now: 09:32 am --> select --> 09:25 - 09:30 am</li>
  <li>Time now: 10:44 pm --> select --> 10:35 - 10:40 pm</li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/MXxte.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MXxte.png" alt="enter image description here"></a></p>
  
  <p>I know how to group my select into 5 minute intervals </p>
  
  <pre><code>date_sub(date_sub(starttime, INTERVAL (MINUTE(starttime) % 5) MINUTE), INTERVAL (SECOND(starttime)) SECOND) as INTERVAL_START,
     date_add(date_sub(date_sub(starttime, INTERVAL (MINUTE(starttime) % 5) MINUTE), INTERVAL (SECOND(starttime)) SECOND), INTERVAL 5 MINUTE) as INTERVAL_END,
  </code></pre>
  
  <p>I also know how to select the last 5 minutes</p>
  
  <pre><code>where  (endtime between now()-Interval 5 minute and now())
  </code></pre>
  
  <p>But how do I get the last full 5 minute interval like shown in the example above?</p>