I have created the following function but seem to be getting an error.
DELIMITER $$
CREATE FUNCTION avg_month(shop INTEGER) RETURNS DECIMAL
BEGIN
DECLARE
avg_m_sales DECIMAL
SELECT TRUNCATE((COUNT(paymentdate) / 12),2) FROM sales_table
WHERE YEAR(paymentdate) = 2017 AND shopid = shop
RETURN avg_m_sales
END $$
DELIMITER ;
I am getting the following error.
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT TRUNCATE((COUNT(payid) / 12),2) FROM fss_Payment WHERE YEAR(paydate) ' at line 5
I also tried adding ; to the end of the statements but when I do this i get the following error:
#1415 - Not allowed to return a result set from a function