title: How to compare values for last and second last entry in table?
body: <p>I have a table in Oracle called quotes with two columns: <i>date</i> and <i>value</i>.</p>
  
  <p>I would like to compare values for last entry and second last entry in the table.</p>
  
  <p>In this example I would like to get dates for <B>13.1 and 11.1 </b> in one line and the difference between the values for each date (10-5=5).</p>
  
  <hr>
  
  <p><b>Quotes Table:</b></p>
  
  <p>Date    -    Value</p>
  
  <p>13.1.2010    -    10</p>
  
  <p>11.1.2010    -     5</p>
  
  <p>10.1.2010    -     2</p>
  
  <p>8.10.2010    -     1</p>
  
  <hr>
  
  <p><H2>Edit:</H2>
  I would like to have more complex table with one more column <I>companyId</I>. I need to get items for each company. Table would look like this:</p>
  
  <p><b>Quotes Table:</b></p>
  
  <p>Date    -    Value       -  CompanyId</p>
  
  <p><b>13.1.2010    -    10     -  10</p>
  
  <p>11.1.2010    -     5     -  10</B></p>
  
  <p>10.1.2010    -     2     -  10</p>
  
  <p>8.10.2010    -     1     -  10</p>
  
  <p><b>12.1.2010    -     7     -  20</p>
  
  <p>10.1.2010    -     3     -  20</B></p>
  
  <p>9.1.2010    -     2     -  20</p>
  
  <p>8.10.2010    -     2     -  20</p>
  
  <p>I would like to get two lines in this case (<I>but in general just get as many lines as the number of companies are</I>) - one for each company that will return both dates and difference between newest value and second newest value.
  So in this case it would return:</p>
  
  <p>companyId 10 13.1 and 11.1 and 5 and another line like this:</p>
  
  <p>companyId 20 12.1 and 10.1 and 4 ( 7-3=4).</p>