title: Remove groups based on multiple conditions
body: <p>I have a table similar to the below. My goal is to remove groups for each date where the status moves to either 'Cancelled' or 'Failed', while retaining groups per day that contain other status changes.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Group</th>
  <th>Status</th>
  <th>Date</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>A</td>
  <td>Pending</td>
  <td>2021-01-01 08:00:00</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Cancelled</td>
  <td>2021-01-01 13:00:00</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Pending</td>
  <td>2021-01-02 08:00:00</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Failed</td>
  <td>2021-01-02 13:00:00</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Pending</td>
  <td>2021-01-03 08:00:00</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Pending Settlement</td>
  <td>2021-01-03 13:00:00</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Pending</td>
  <td>2021-01-04 08:00:00</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Settled</td>
  <td>2021-01-04 13:00:00</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Pending</td>
  <td>2021-01-01 08:00:00</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Cancelled</td>
  <td>2021-01-01 13:00:00</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Pending</td>
  <td>2021-01-02 08:00:00</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Failed</td>
  <td>2021-01-02 13:00:00</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Pending</td>
  <td>2021-01-03 08:00:00</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Pending Settlement</td>
  <td>2021-01-03 13:00:00</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Pending</td>
  <td>2021-01-04 08:00:00</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Settled</td>
  <td>2021-01-04 13:00:00</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>My first attempt was something like:</p>
  <pre><code>select GROUP, STATUS, DATE
  from TABLE TBL
  , (
  select GROUP, STATUS, DATE
  from TABLE
  where STATUS in ('Cancelled','Failed')
  ) FLAG
  where (TBL.GROUP &lt;&gt; FLAG.GROUP and TBL.DATE &lt;&gt; FLAG.DATE)
  ;
  </code></pre>
  <p>My expected output is shown below <em>EDIT:, however it seems to be taking exceptionally long (&gt;10 mins) even when applying date filters</em>:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Group</th>
  <th>Status</th>
  <th>Date</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>A</td>
  <td>Pending</td>
  <td>2021-01-03 08:00:00</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Pending Settlement</td>
  <td>2021-01-03 13:00:00</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Pending</td>
  <td>2021-01-04 08:00:00</td>
  </tr>
  <tr>
  <td>A</td>
  <td>Settled</td>
  <td>2021-01-04 13:00:00</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Pending</td>
  <td>2021-01-03 08:00:00</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Pending Settlement</td>
  <td>2021-01-03 13:00:00</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Pending</td>
  <td>2021-01-04 08:00:00</td>
  </tr>
  <tr>
  <td>B</td>
  <td>Settled</td>
  <td>2021-01-04 13:00:00</td>
  </tr>
  </tbody>
  </table>
  </div>