title: Compare values in Sql query
body: <p>I have some tables and sql query with join to select from this tables. 
  Query result looks like:</p>
  
  <pre><code>number|name |value
  ------------------
  1     |name1| 2.48
  2     |name1| 1.32
  3     |name1| 1.32
  </code></pre>
  
  <p>I need to rewrite this query to add one more field depends of comparison of value field. For example: if it is the first row I need 0, if previous value bigger then I need 1, else 2.</p>
  
  <p>Result I want to have looks like this:</p>
  
  <pre><code>number|name |value|status
  --------------------------
  1     |name1| 2.48|0
  2     |name1| 1.32|2
  3     |name1| 1.57|1
  </code></pre>
  
  <p>Also I know about case when, but I don't know how I can compare values. The best way, as I see, to iterate through all rows in the result. May be there is some other ways?</p>