我最近开始研究 MySQL n 现在我想创建一个触发器,但 MySQL 在我的语法中返回一个错误。
delimiter $$;
create trigger abc after insert on ratings
for each row
begin
set @n1 = select avg(rating) from ratings join users where ratings.uname=users.uname
and ratings.bookid=new.bookid users.`type`='admin' or users.`type`='critic';
update books set avgcriticrating = @n1 where bookid=new.bookid;
end;
select 语句在自己触发时运行完美,但当我在触发器内使用它时会出错。
这是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 'select avg(rating) from ratings join users where ratings.uname=users.uname an' at line 4
book 和 rating 表都包含一个名为 bookid 的字段。
请帮忙