检查mySQL是否正确

发布于 2024-08-16 19:41:13 字数 840 浏览 3 评论 0原文

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

谢谢^_^

PHPmyAdmin keeps rejecting this mySQL im pretty sure its right and don't actually need it to run, its uni work and just have to hand in, it looks right to me.

the actual error I get is

#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 

I have tried playing with adding and removing ; to LIMIT and END nether of which help , were am I being stupid?

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

thanks ^_^

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

就是爱搞怪 2024-08-23 19:41:13

您必须更改分隔符。至少在 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

You have to change the delimiter. At least in the MySQL client you do this:

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文