Попробуйте это:
CREATE DEFINER=`root`@`localhost` PROCEDURE `calculateLeadTime`(
IN product varchar(64))
BEGIN
SET @lastDate = (SELECT sessionDate FROM stock
WHERE product = (%s)
ORDER BY stocksessionID DESC LIMIT 1);
SET @secondLastDate = (SELECT sessionDate FROM stock WHERE product = (%s)
ORDER BY stocksessionID DESC LIMIT 1, 1);
SET @leadTime = (SELECT DATEDIFF(@lastDate, @secondLastDate));
SET @lastStockSessionID = (SELECT stocksessionID
FROM stock WHERE product = (%s) ORDER BY stocksessionID DESC LIMIT 1);
UPDATE stock SET leadTime = (@leadTime)
WHERE stocksessionID = @lastStockSessionID;
END
и при вызове процедуры
cursor.execute('{CALL [calculateLeadTime](?)}',
('value'))
или
cursor.callproc('calculateLeadTime', ['product_name, ])
Передайте значение вашего продукта