I'm trying to create a mysql function to calculate the total spent by the top five customers in a store but I keep receiving the following syntax error. What is causing the error? Error:
ERROR 1064 (42000): 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
'FUNCTION costofbestbuyers (totalspent DECIMAL)
RETURNS DOUBLE
BEGIN
DECLA' at line 1
Function:
DELIMITER //
CREATE FUNCTION topfivespenders (totalspent DECIMAL)
RETURNS DOUBLE
BEGIN
DECLARE totalspent DOUBLE DEFAULT 0;
SELECT sum(ordercost) AS totalspent
FROM customer c JOIN orders o
ON c.customerID = o.cID
GROUP BY o.cID
ORDER BY totalspent desc
LIMIT 5;
RETURN totalspent;
END; //