I have a MS SQL table that contains stock data with the following columns: Id, Symbol, Date, Open, High, Low, Close.
Id, Symbol, Date, Open, High, Low, Close
I would like to self-join the table
Index on (symbol, date)
(symbol, date)
SELECT * FROM quotes q_curr CROSS APPLY ( SELECT TOP(1) * FROM quotes WHERE symbol = q_curr.symbol AND date < q_curr.date ORDER BY date DESC ) q_prev