title: How to write an SQL statement that gets a row if the rest of the rows with the same userID are not a certain condition?
body: <p>Given the following table:</p>
  
  <pre><code>userId |    State     |  Number
  --------------------------------
   123   |   waiting    |   3
   123   |  processing  |   2
   123   |  completed   |   1
  </code></pre>
  
  <p>How can I get the row for a single user with <code>State = waiting</code> state given a <code>Number</code> (let's say <code>3</code> in this case) only if there is no row for the same user with a lower <code>Number</code> and is in the <code>processing</code> state.</p>
  
  <p>In this example, the query would <em>not</em> return a row. If row labeled <code>Number = 2</code> was <code>State = completed</code> (instead of <code>State = processing</code>), then the query would return the whole row labeled <code>Number = 3</code>.</p>