title: Postgres Order by multi columns with a condition
body: <p>I want to order a Postgres query depending on conditions in the table</p>
  
  <pre><code>    id   sensor_id            alarmTime            clearedTime
  415068        3734  2016-04-20 12:25:32    2016-04-27 21:05:44  
  415070        3734  2016-04-21 12:25:32                   null
  415071        3734  2016-03-22 12:25:32    2016-04-29 21:15:44          
  415072        3734  2016-04-23 12:25:32                   null          
  415073        3734  2016-04-20 12:25:32    2016-04-22 22:05:45          
  415074        3734  2016-02-26 12:25:32    2016-04-27 23:15:24  
  </code></pre>
  
  <p>From the above table I want to initially order by nulls first and alarm time with the remaining rows ordered by cleared time only. to get some thing like this</p>
  
  <pre><code>    id   sensor_id            alarmTime            clearedTime
  415070        3734  2016-04-21 12:25:32                   null
  415072        3734  2016-04-23 12:25:32                   null  
  415068        3734  2016-04-20 12:25:32    2016-04-27 21:05:44  
  415073        3734  2016-04-20 12:25:32    2016-04-22 22:05:45          
  415071        3734  2016-03-22 12:25:32    2016-04-29 21:15:44          
  415074        3734  2016-02-26 12:25:32    2016-04-27 23:15:24  
  </code></pre>
  
  <p>I have tried something like this</p>
  
  <pre><code>select * from table
  ORDER BY
  case alarm.clearedTime is NOT NULL
  when TRUE THEN alarmTime
  else clearedTime
  end  DESC NULLS FIRST;
  </code></pre>