title: Teradata/SQL, select all rows until a certain value is reached per partition
body: <p>I'd like to select all rows from a table until (and including) a certain value is reached per partition. In this case all rows per id that precede when status has the value 'b' for the last time. Note: the timestamp is in order per id</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>name</th>
  <th>status</th>
  <th>status</th>
  <th>timestamp</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>Sta</td>
  <td>open</td>
  <td>a</td>
  <td>10:50:09.000000</td>
  </tr>
  <tr>
  <td>1</td>
  <td>Danny</td>
  <td>open</td>
  <td>c</td>
  <td>10:50:19.000000</td>
  </tr>
  <tr>
  <td>1</td>
  <td>Elle</td>
  <td>closed</td>
  <td>b</td>
  <td>10:50:39.000000</td>
  </tr>
  <tr>
  <td>2</td>
  <td>anton</td>
  <td>closed</td>
  <td>a</td>
  <td>16:00:09.000000</td>
  </tr>
  <tr>
  <td>2</td>
  <td>jill</td>
  <td>done</td>
  <td>b</td>
  <td>16:00:19.000000</td>
  </tr>
  <tr>
  <td>2</td>
  <td>tom</td>
  <td>open</td>
  <td>b</td>
  <td>16:05:09.000000</td>
  </tr>
  <tr>
  <td>2</td>
  <td>bill</td>
  <td>open</td>
  <td>c</td>
  <td>16:07:09.000000</td>
  </tr>
  <tr>
  <td>3</td>
  <td>ann</td>
  <td>done</td>
  <td>b</td>
  <td>08:00:13.000000</td>
  </tr>
  <tr>
  <td>3</td>
  <td>stef</td>
  <td>done</td>
  <td>b</td>
  <td>08:12:13.000000</td>
  </tr>
  <tr>
  <td>3</td>
  <td>martin</td>
  <td>open</td>
  <td>b</td>
  <td>08:25:13.000000</td>
  </tr>
  <tr>
  <td>3</td>
  <td>jeff</td>
  <td>open</td>
  <td>a</td>
  <td>09:00:13.000000</td>
  </tr>
  <tr>
  <td>3</td>
  <td>luke</td>
  <td>open</td>
  <td>c</td>
  <td>09:07:13.000000</td>
  </tr>
  <tr>
  <td>3</td>
  <td>karen</td>
  <td>open</td>
  <td>c</td>
  <td>09:15:13.000000</td>
  </tr>
  <tr>
  <td>3</td>
  <td>lucy</td>
  <td>open</td>
  <td>a</td>
  <td>10:00:13.000000</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The output would look like this:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>name</th>
  <th>status</th>
  <th>status</th>
  <th>timestamp</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>Sta</td>
  <td>open</td>
  <td>a</td>
  <td>10:50:09.000000</td>
  </tr>
  <tr>
  <td>1</td>
  <td>Danny</td>
  <td>open</td>
  <td>c</td>
  <td>10:50:19.000000</td>
  </tr>
  <tr>
  <td>1</td>
  <td>Elle</td>
  <td>closed</td>
  <td>b</td>
  <td>10:50:39.000000</td>
  </tr>
  <tr>
  <td>2</td>
  <td>anton</td>
  <td>closed</td>
  <td>a</td>
  <td>16:00:09.000000</td>
  </tr>
  <tr>
  <td>2</td>
  <td>jill</td>
  <td>done</td>
  <td>b</td>
  <td>16:00:19.000000</td>
  </tr>
  <tr>
  <td>2</td>
  <td>tom</td>
  <td>open</td>
  <td>b</td>
  <td>16:05:09.000000</td>
  </tr>
  <tr>
  <td>3</td>
  <td>ann</td>
  <td>done</td>
  <td>b</td>
  <td>08:00:13.000000</td>
  </tr>
  <tr>
  <td>3</td>
  <td>stef</td>
  <td>done</td>
  <td>b</td>
  <td>08:12:13.000000</td>
  </tr>
  <tr>
  <td>3</td>
  <td>martin</td>
  <td>open</td>
  <td>b</td>
  <td>08:25:13.000000</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I've tried to solve this using qualify with rank etc. but unfortunately with no succes. would be appreciated if somebody would be able to help me!</p>