title: Pairwise swapping of rows in sql
body: <p>I have a device settings table with threshold types and values.
  Let's say <em>ThresholdType = 0 is Min and ThresholdType = 1 is Max</em>
  The initial table looks like this:
  <br/></p>
  <pre><code>DeviceID    ThresholdType  ThresholdValue
  1           0              5  
  1           1              10
  2           0              15  
  2           1              20
  3           0              21  
  3           1              34
  4           0              1 
  4           1              8    
  </code></pre>
  <p>Then I had to change ThresholdType meaning - <em>0 became Max threshold and 1 became Min one</em>.</p>
  <p>I want the table look like that:</p>
  <pre><code>DeviceID    ThresholdType  ThresholdValue
  1           0              10  
  1           1              5
  2           0              20  
  2           1              15
  3           0              34  
  3           1              21
  4           0              8 
  4           1              1  
  </code></pre>
  <p>Is it possible to change update it with a single SQL without loops?</p>