title: Better way to format CASE containing multiple nested SELECTS
body: <p>I want to do this:</p>
  
  <pre><code>SELECT (EXTRACT(epoch FROM (
  case when 
      (select date from history where statut='X' and id=6 order by date desc limit 1) 
       is null then now() 
    else 
      (select date from history where statut='X' and id=6 order by date desc limit 1) end)
  - case when 
      (select date from history where statut in ('Y', 'U') and id=6 order by date desc limit 1) 
       is null then now() 
  else 
   (select date from history where statut in ('Y', 'U')  and id=6 order by date desc limit 1) 
   end 
  )/3600)
  </code></pre>
  
  <p>This request search in history date of modification for certain statuts, subtracts it, and returns difference in hours. 
  In case no line is found it should be replaced by 0.</p>
  
  <p>It works but we can all see how ugly it is.</p>
  
  <p>Is there a way to beautify my query?</p>