title: SQL Column with Max Values where seperate column = 1
body: <p>I have a table similar to below:</p>
  
  <pre><code>+-----+-----------+--------+--------+
  | key | timestamp | event1 | event2 |
  +-----+-----------+--------+--------+
  | 123 | 07:06     | 1      | 0      |
  | 123 | 07:21     | 1      | 0      |
  | 123 | 07:59     | 0      | 1      |
  | 123 | 08:02     | 0      | 1      |
  | 456 | 14:21     | 1      | 0      |
  | 456 | 15:02     | 0      | 1      |
  | ... | ...       | ...    | ...    |
  +-----+-----------+--------+--------+
  </code></pre>
  
  <p>And I'm looking to get one row for each key, where the next two columns are the <strong>minimum</strong> values of event1 and the <strong>maximum</strong> values of event2, and then (fingers crossed) a delta between the two times.</p>
  
  <pre><code>+-----+--------+--------+-------+
  | key | event1 | event2 | delta |
  +-----+--------+--------+-------+
  | 123 | 07:06  | 08:02  | 00:54 |
  | 456 | 14:21  | 15:02  | 00:41 |
  | ... | ...    | ...    | ...   |
  +-----+--------+--------+-------+
  </code></pre>
  
  <p>So far I've tried a <code>max</code> function where <code>event1</code> = 1 however I get the overall maximum value of <code>event1</code> alongside every key value regardless of whether or not that key had that value at any point.</p>