title: comparing current row and previous in oracle sql
body: <p>I need to compare current row and previous row and based on some comparision need to derive a column value. Currently apporach I m following is making two differnt record sets and then use rank function and then by joining rank functions I m able to achiieve this. However, this seems to be tedious apporach, is there a better way to achieve this. I m currently writing query something like below :- </p>
  
  <pre><code>    select 
  &lt; comparing columns from two record sets and deriving column value&gt; 
                (
          select(&lt;some complex logic&gt;, rank from a) rcdset, 
      (select &lt;some complex logic&gt;, rank +1 from a) rcdset2 where rcdset.rnk = rcdset1.rnk (+)
  </code></pre>
  
  <p>Database - Oracle 10g</p>