检查mySQL是否正确

时间:2010-01-07 22:30:48

标签: mysql stored-procedures phpmyadmin

PHPmyAdmin一直拒绝这个mySQL我非常肯定它是正确的,并且实际上并不需要它运行,它的单一工作只需要交付,它看起来对我来说。

我得到的实际错误是

#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 'END' at line 23 

我尝试过添加和删除游戏;在LIMIT和END下面有哪些帮助,我是不是很蠢?

CREATE PROCEDURE topFive(
   IN PID VARCHAR(6),
   IN CID VARCHAR(6)
)
BEGIN

SELECT `OrderItem`.`ProductID` , COUNT(*) AS `Popularity`
FROM `OrderItem`,
(
SELECT `Order`.`OrderID`
FROM `OrderItem`,`Order`
WHERE
(`Order`.`OrderID`=`OrderItem`.`OrderID`)
AND 
(`OrderItem`.`ProductID`=PID)
AND
(`Order`.`CustomerID`!=CID)
) AS `ORDER_ID_TABLE`
WHERE  (`OrderItem`.`OrderID` = `ORDER_ID_TABLE`.`OrderID`)
GROUP BY `OrderItem`.`ProductID`
ORDER BY `Popularity`
LIMIT 0,5

END

谢谢^ _ ^

1 个答案:

答案 0 :(得分:0)

您必须更改分隔符。至少在MySQL客户端中你这样做:

DELIMITER //

CREATE PROCEDURE topFive(
   IN PID VARCHAR(6),
   IN CID VARCHAR(6)
)
BEGIN

SELECT `OrderItem`.`ProductID` , COUNT(*) AS `Popularity`
FROM `OrderItem`,
(
SELECT `Order`.`OrderID`
FROM `OrderItem`,`Order`
WHERE
(`Order`.`OrderID`=`OrderItem`.`OrderID`)
AND 
(`OrderItem`.`ProductID`=PID)
AND
(`Order`.`CustomerID`!=CID)
) AS `ORDER_ID_TABLE`
WHERE  (`OrderItem`.`OrderID` = `ORDER_ID_TABLE`.`OrderID`)
GROUP BY `OrderItem`.`ProductID`
ORDER BY `Popularity`
LIMIT 0,5//

END