title: Group by adjacent time values
body: <p>I hope someone can help with that tricky question:</p>
  
  <p>How can I "GROUP BY" some rows which have a configurable adjacent distance between the timestamps?</p>
  
  <p>Example table:</p>
  
  <pre><code>ID     | Value | When
  1      | 5     | 2017-06-30 11:45:55
  2      | 9     | 2017-06-30 11:45:56
  3      | 0     | 2017-06-30 11:45:59
  4      | 2     | 2017-06-30 11:46:02
  5      | 7     | 2017-06-30 17:19:22
  6      | 7     | 2017-06-30 17:19:22
  7      | 3     | 2017-06-30 17:19:22
  8      | 6     | 2017-06-30 17:19:22
  </code></pre>
  
  <p>Desired result:</p>
  
  <pre><code>ID     | Value | When
  3      | 0     | 2017-06-30 11:45:59
  7      | 3     | 2017-06-30 17:19:22
  </code></pre>
  
  <p>The result shall find adjacent entries (in the example two groups of four rows each) and tell the lowest "Value".
  Adjacent distance can be any value like one minute or ten minutes.</p>
  
  <p>I tried to reformat the date to be able to "GROUP BY" without seconds but this won't work for the first result.</p>
  
  <p>My MySQL programming skills are limited but it could be done with following steps:</p>
  
  <ol>
  <li>SELECT and ORDER BY "When"</li>
  <li>Go though values and tell difference between current and previous "When" value, if within range, then GROUP, if not output a new row.</li>
  </ol>
  
  <p>Any idea?</p>