title: Reorder a table for/before a case/when clause
body: <p>I have a query, with some case When clause.</p>
  
  <p>I use then , the function lead(or lag) to check other lines.</p>
  
  <p>The problem is, I check it, in the order of the table, without order. So it will not be always in the good order in my result.</p>
  
  <pre><code> CASE
            WHEN Lead(s.id_location, 1, NULL) OVER (ORDER BY s.id_location) = s.id_location THEN  'at the same address '
            ELSE '\par \tab ' ||s.dir || '\par \tab '|| s.address || '\par \tab salle ' || s.lib_ || '\par \tab '|| s.etage  
          END AS adresscomplete, 
  </code></pre>
  
  <p>I got a date associated that can order by. But
   the problem is that the wrong line can have the "at the same address" text, because I do not choose the order it made the lead(or lag).
  So, This can be as result : </p>
  
  <p>My direction, my address my salle .... at the same address 
  or
  at the same address .... My direction, my address my salle</p>
  
  <p>The second is obvisouly wrong</p>
  
  <p>Can I choose, before going into my case, to order the lines by date, so it will always the second, that will be with "at the same address" text.</p>
  
  <p>This should be</p>
  
  <p>My direction, my address my salle first date .... at the same address second date 
  and not </p>
  
  <p>at the same address date .... My direction, my address my salle second date </p>
  
  <p>Thank you. </p>