gpt4 book ai didi

MYSQL 触发器语法错误。第1064章

转载 作者:行者123 更新时间:2023-11-30 00:24:32 24 4
gpt4 key购买 nike

delimiter //
CREATE TRIGGER Raiting_added AFTER INSERT ON raiting
FOR EACH ROW
BEGIN

declare del INT;
SET del = (SELECT COUNT( rait_id ) FROM `raiting` WHERE NEW.movie_id AND user = NEW.user);

IF del > 0 THEN
DELETE FROM movies WHERE movie_id = NEW.movie_id AND user = NEW.user
END IF;

UPDATE movies
SET raiting = ( SELECT ROUND( AVG( seted_rait ) , 1 )
FROM `raiting`
WHERE movie_id = NEW.movie_id)
WHERE movie_id = NEW.movie_id
END
delimiter;

Error : #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 IF; UPDATE movies SET raiting = ( SELECT ROUND( AVG( seted_rait ) , 1 ) ' at line 10

有什么问题吗?有人可以帮忙吗?

最佳答案

您忘记了“= movie_id”和几个分号

delimiter //
CREATE TRIGGER Raiting_added AFTER INSERT ON raiting
FOR EACH ROW
BEGIN

declare del INT;
SET del = (SELECT COUNT( rait_id ) FROM `raiting` WHERE NEW.movie_id AND user = NEW.user);

IF del > 0 THEN
DELETE FROM movies WHERE movie_id = NEW.movie_id AND user = NEW.user;
END IF;

UPDATE movies
SET raiting = ( SELECT ROUND( AVG( seted_rait ) , 1 )
FROM `raiting`
WHERE movie_id = NEW.movie_id)
WHERE movie_id = NEW.movie_id;
END;
//
delimiter ;

关于MYSQL 触发器语法错误。第1064章,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22987876/

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