为什么我的扳机不起作用?

时间:2012-08-19 11:09:11

标签: mysql triggers

我的触发器:

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

1 个答案:

答案 0 :(得分:2)

您需要将WHERE子句置于GROUP BY子句之前。

select count(*)
into @num
from tc_contract
where account_id = new.account_id
group by account_id;