title: sql select min or max based on condition
body: <p>Hi all I'm trying to find a way to select min or max from a range of data based on these conditions:  </p>
  
  <ul>
  <li>If setuptime and processtime cols are all 0 select MIN(oprNum)
  (operation hasn't started yet so get first oprnum)  </li>
  <li>If setuptime and process time are not 0, get max oprnum (active operation).  </li>
  </ul>
  
  <p>Based on either of these I want ONE row... Please see attached example of data. Thanks! This is part of a much larger query so i need 1 output row per prodid...</p>
  
  <pre><code>+------------+--------+---------+--------------------+--------------------+
  | ProdId     | OprNum | Company | SetupTime          | ProcessTime        |
  +------------+--------+---------+--------------------+--------------------+
  | 12M0003381 | 10     | 12      | 1.3400000000000000 | 1.6100000000000000 |
  +------------+--------+---------+--------------------+--------------------+
  | 12M0003381 | 10     | 12      | 0.0000000000000000 | 0.0000000000000000 |
  +------------+--------+---------+--------------------+--------------------+
  | 12M0003381 | 15     | 12      | 1.0000000000000000 | 0.0000000000000000 |
  +------------+--------+---------+--------------------+--------------------+
  | 12M0003381 | 50     | 12      | 0.0000000000000000 | 0.0000000000000000 |
  +------------+--------+---------+--------------------+--------------------+
  | 12M0003381 | 60     | 12      | 0.0000000000000000 | 0.0000000000000000 |
  +------------+--------+---------+--------------------+--------------------+
  | 12M0003381 | 60     | 12      | 0.0000000000000000 | 0.0000000000000000 |
  +------------+--------+---------+--------------------+--------------------+
  | 12M0003381 | 70     | 12      | 0.0700000000000000 | 0.0400000000000000 |
  +------------+--------+---------+--------------------+--------------------+
  | 12M0003381 | 70     | 12      | 0.0000000000000000 | 0.0000000000000000 |
  +------------+--------+---------+--------------------+--------------------+
  </code></pre>