Ok, llegué a casa y pude resolver esto.
SELECT stock_id, t1.price AS `then`, t2.price AS `now`, ROUND(t2.price - t1.price, 2) AS `difference`
FROM (
SELECT stock_id, price, date FROM share_prices sp
WHERE date = (SELECT MIN(date) FROM share_prices sp2
WHERE date BETWEEN '2010/02/23 10:00:00'
AND '2010/02/24 10:00:00'
AND sp2.stock_id = sp.stock_id)
) t1
JOIN
(
SELECT stock_id, price, date FROM share_prices sp
WHERE date = (SELECT MAX(date) FROM share_prices sp2
WHERE date BETWEEN '2010/02/23 10:00:00'
AND '2010/02/24 10:00:00'
AND sp2.stock_id = sp.stock_id)
) t2 USING(stock_id)
ORDER BY `difference` DESC
Utiliza los resultados de 2 subconsultas, cada una con su propia subconsulta al primer y último registro, respectivamente, para ese rango.
Estaba usando integer
para stock_id
, float
por price
y timestamp
para la fecha, ya que puede haber problemas (especialmente con MIN y MAX) con otros tipos de datos.