table: t_instrument_price
InstrumentID
InstrumentPrice
PriceDate
example data:
InstrumentID InstrumentPrice PriceDate
1 82.03 07/25/2017
1 82.08 07/24/2017
1 81.97 07/21/2017
2 115 07/25/2017
2 114.5 07/24/2017
2 113; 07/21/2017
Really struggling with the following:
I would like to join t_instrument_price with itself ON InstrumentID AND on the closest earlier date in order to get the previous available price (not necessarily the previous day as there are no prices during weekend/holidays.etc) . Up until now I didn't manage to come close to a solution. Can anybody help? Would be very appreciated...
expected result
InstrumentID InstrumentPrice PriceDate PreviousPrice PreviousDatePrice
1 82.03 07/25/2017 82.08 07/24/2017
1 82.08 07/24/2017 81.97 07/21/2017
2 115 07/25/2017 114.5 07/24/2017
2 114.5 07/24/2017 113 07/21/2017