title: How to rank columns of a same row in Oracle SQL
body: <p>I have the following row in a table:</p>
  
  <pre><code>C1 |C2 |C3 |C4
  
   7 | 3 | 1 | 6
  </code></pre>
  
  <p>I would like to construct a query in such a way that an order is given to each column;</p>
  
  <pre><code>O1 |O2 |O3 |O4
   4 | 2 | 1 | 3
  </code></pre>
  
  <p>Is it possible to do this kind of row-by-row comparisons in a single query? Or is the only option to construct a complex <em>case when</em> statement?</p>
  
  <p>Edit: the case when I am trying to bypass:</p>
  
  <pre><code>case 
      when C1 = greatest ( C1, C2, C3, C4) then 1
      when C1 &gt;= C2 and C1 &gt;= C3 and C1 &lt; C4
        or C1 &gt;= C2 and C1 &lt;  C3 and C1 &gt;= C4
        or C1 &lt;  C2 and C1 &gt;= C3 and C1 &gt;= C4 then 2
      when C1 &gt;= C2 and C1 &lt;  C3 and C1 &lt;  C4
        or C1 &lt;  C2 and C1 &gt;= C3 and C1 &lt;  C4
        or C1 &lt;  C2 and C1 &lt;  C3 and C1 &gt;= C4 then 3
      when C1 = least (C1, C2, C3, C4 ) then 4 
  end as O1
  </code></pre>
  
  <p>In case of equal values, the index determines the order: if C2 = C3, O2 = 1, O2 = 3.</p>
  
  <p>As you can image, this is quite prone to errors. Is there a way to do this comparison more elegant?</p>
  
  <p>The comparison only needs to happen in a single row, the ordering of the columns in a single does not influence the order of the rows in the table. </p>
  
  <p>Edit 2: there are multiple rows in the table, identified with ID_ROW.</p>