触发器内select语句中的MySQL错误
我最近开始研究MySQL n,现在我想创建一个触发器,但是MySQL在语法上返回了一个错误触发器内select语句中的MySQL错误,mysql,select,triggers,Mysql,Select,Triggers,我最近开始研究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
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
books和ratings表都包含一个名为bookid的字段
请帮助如果希望从select语句中获得单个值,则该语句必须位于(括号)中 下一个错误将发生在
new.bookid用户处
-可能有和或缺失
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');