【发布时间】:2018-03-27 05:07:40
【问题描述】:
我正在尝试创建一个 mysql 函数来计算商店中前五名客户的总支出,但我不断收到以下语法错误。是什么导致了错误? 错误:
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; //
【问题讨论】:
标签: mysql user-defined-functions