If the dates in your table increment by 1 all the time, you could try this:
Code:
SELECT p1.product, SUM(p1.stock - p2.stock) sold
FROM product p1, product p2
WHERE p1.product = p2.product
AND p2.stock < p1.stock
AND p2.dt = p1.dt + 1
GROUP BY p1.product;
But, if you have gaps between dates, you'll need a subquery to find out the right date:
Code:
... AND p2.dt =
(SELECT MIN(p3.dt) FROM product p3
WHERE p3.product = p1.product
AND p3.dt > p1.dt
)
I hope this helps ...