gpt4 book ai didi

mysql - SQL 查询从 IDE 运行,但不在 phpmyadmin 中运行

转载 作者:行者123 更新时间:2023-12-01 00:41:07 25 4
gpt4 key购买 nike

我有这段 SQL 代码:

CREATE EVENT `update_statistics`
ON SCHEDULE EVERY 1 DAY STARTS '2015-08-24 02:00:00'
ON COMPLETION PRESERVE
DO BEGIN

UPDATE statistics
SET km_traveled = (SELECT sum(km)
FROM archived_trips),
passengers_driven = (SELECT sum(passengers)
FROM archived_trips),
trips_taken = (SELECT count(*)
FROM archived_trips)
WHERE id = 1;

UPDATE statistics
SET co_saved = ((SELECT km_traveled
FROM statistics) * 0.215 * (SELECT passengers_driven
FROM statistics))
WHERE id = 1;

END;

当我通过 PhpStorm 中的 SQL 控制台运行它时 - 它运行良好,计划任务正常运行等等。

但是如果我尝试直接在 phpmyadmin 中运行查询,我会收到以下错误:

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

第 13 行是 WHERE id=1;。老实说,我没有发现查询有任何语法问题。有什么建议吗?

最佳答案

查询的分隔符是';'和 ';'存储过程中也用到了,导致查询失败。

在语句前添加 DELIMITER// 并以 // 结尾来解决这个问题。

DELIMITER //

CREATE EVENT `update_statistics`
ON SCHEDULE EVERY 1 DAY STARTS '2015-08-24 02:00:00'
ON COMPLETION PRESERVE
DO BEGIN

UPDATE statistics
SET km_traveled = (SELECT sum(km)
FROM archived_trips),
passengers_driven = (SELECT sum(passengers)
FROM archived_trips),
trips_taken = (SELECT count(*)
FROM archived_trips)
WHERE id = 1;

UPDATE statistics
SET co_saved = ((SELECT km_traveled
FROM statistics) * 0.215 * (SELECT passengers_driven
FROM statistics))
WHERE id = 1;

END; //

DELIMITER ;

使用 PHPstorm,一次发送多个查询可能被禁用,导致 MySQL 忽略分隔符。

关于mysql - SQL 查询从 IDE 运行,但不在 phpmyadmin 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32258056/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com