我正在嘗試創建一個mysql函數來計算商店中前五位客戶所花費的總額,但我一直收到以下語法錯誤。什麼導致了錯誤? 錯誤:使用mysql用戶定義的函數來計算美元金額。錯誤1064(42000)
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
功能:
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; //