I have a table full of prices, items, and dates. An example of this is:
AA, 1/2/3024, 1.22
AA, 1/3/3024, 1.23
BB, 1/2/3024, 4.22
BB, 1/3/3024, 4.23
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].
The result should look like
AA, todays price-yesterdays price
Despite being a sum function, there is no subtraction function over a list.
I'm using postgres 9.1.