I have the following mySQL (v5.7) Stored Procedure which works great (it calculates the average of the most recent 25 rows):
CREATE DEFINER=`SqueezeOJ`@`%` PROCEDURE `NVG_SMA25`(
IN myDate DATE,
OUT mySMA25 DECIMAL(8,2)
)
BEGIN
SELECT ROUND(AVG(ClosingPrice), 2) INTO mySMA25 FROM NVG
WHERE TradeDate IN (SELECT * FROM (SELECT DISTINCT TradeDate
FROM NVG
WHERE TradeDate <= myDate
ORDER BY TradeDate DESC LIMIT 25) as calculating);
END
I'd like to parameterize the LIMIT 25 to LIMIT X - where I can pass X into the procedure, but everything I try leads to errors.
Can someone point me in the right direction?
Thanks, Jason