Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
触发器内select语句中的MySQL错误_Mysql_Select_Triggers - Fatal编程技术网

触发器内select语句中的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

我最近开始研究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
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');