我的触发器:
create trigger cnt after insert on tc_contract
for each rowbegin
select count(*) into @num from tc_contract group by account_id where account_id = new.account_id;
if @num >0 and @num <3 then
update tc_account set account_status = 2 where account_id = new.account_id;
end if;
end
错误消息:
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 'where account_id = new.account_id;
if @num >0 and @num <3 then update tc_accou' at line 4
答案 0 :(得分:2)
您需要将WHERE
子句置于GROUP BY
子句之前。
即
select count(*)
into @num
from tc_contract
where account_id = new.account_id
group by account_id;