title: Group rows if certain column value directly after another in SQL
body: <p>I'm using MS SQL Server 2008, and I would like this:</p>
  
  <pre><code>+------+--------+--------+------------+
  | id   | Name   | Event  | Timestamp  |
  +------+--------+--------+------------+
  |    0 | bob    | note   | 14:20      |
  |    1 | bob    | time   | 14:22      |
  |    2 | bob    | time   | 14:40      |
  |    3 | bob    | time   | 14:45      |
  |    4 | bob    | send   | 14:48      |
  |    5 | bob    | time   | 15:30      |
  |    6 | bob    | note   | 15:35      |
  |    7 | bob    | note   | 18:00      |
  +------+--------+--------+------------+
  </code></pre>
  
  <p>To become this:</p>
  
  <pre><code>+------+--------+--------+------------+
  | id   | Name   | Event  | Timestamp  |
  +------+--------+--------+------------+
  |    0 | bob    | note   | 14:20      |
  |    1 | bob    | time   | 14:22      |
  |    4 | bob    | send   | 14:48      |
  |    5 | bob    | time   | 15:30      |
  |    6 | bob    | note   | 15:35      |
  +------+--------+--------+------------+
  </code></pre>
  
  <p>I.e., rows are "grouped" by the "event" column. Only one of each <em>grouped</em> identical "event" is to be shown.</p>
  
  <ul>
  <li>If one event, e.g. "note" as with id 0, is in the table with no row directly before or after it (row with nearest timestamps) that has an equal "event" value, it is shown;</li>
  <li>If more than one row with the same event, e.g. "time" as with id 1-3. comes after each others (i.e. no row with a different "event" has a timestamp that is "between" them), any one of them is shown (doesn't matter for me, all other columns are identical anyway).</li>
  </ul>
  
  <p>Those two are the only rules.</p>