title: Aggregation function to get the difference or ratio of two rows in order
body: <p>I have a table full of prices, items, and dates. An example of this is:</p>
  
  <pre><code>AA, 1/2/3024, 1.22
  AA, 1/3/3024, 1.23
  BB, 1/2/3024, 4.22
  BB, 1/3/3024, 4.23
  </code></pre>
  
  <p>Within the data there are only two rows per price, and they are ordered by date. How would I condense this data set into a single product row showing the difference from the last price to the previous? [Also this applies to a ratio, so AA would produce 1.23/1.22]. </p>
  
  <p>The result should look like</p>
  
  <pre><code>AA, todays price-yesterdays price
  </code></pre>
  
  <p>Despite being a sum function, there is no subtraction function over a list.</p>
  
  <p>I'm using postgres 9.1.</p>