I have a table which has columns of price and date, ordered by the ascending dates. I need to calculate from this a return vector where return = price ( i) / price ( i- 1). The time is not time based, which means that one record can be at 9h34, the next at 9h35, then 9h40 etc…
I have found the following topic:
SQL Syntax for calculating results of returned data
but in Oracle I can’t use order by in a subquery, could you please help me?
In Oracle, you could use the
laganalytic function:Here,
lag(price) over (order by i)returns the price of the previous row, in a set ordered by theicolumn.