-1

我的触发器:

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
4

1 回答 1

2

您需要将子句放在WHERE子句之前GROUP BY

IE

select count(*)
into @num
from tc_contract
where account_id = new.account_id
group by account_id;
于 2012-08-19T11:18:59.020 回答