0

我写了以下代码:

create trigger money after update on `things`
for each row
begin
   Select @c1=sum(`thing_cost`) from `things`
   UNION
   Select @c2=sum(`salary`) from `dude_base`
   Update `current` set `curr_cash`=@c1*@c2/100
end;
$$

表“东西”有:

id1 (PK)
name
thing_cost

表 dude_base 有:

id2 (PK)
salary
name, etc. irrevelant

表电流有:

id1 (FK)
id2(FK)
curr_cash

我收到以下错误:

 #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 'Update `current` set `curr_cash`=@c1*@c2/100; END' at line 7

有什么帮助吗?

4

1 回答 1

1

我认为你应该有一个;分号

Select @c2=sum(`salary`) from `dude_base`;

结束此查询,因为UPDATE是另一个查询

// 编辑

像这样试试

SET @c1 = (SELECT sum(`thing_cost`) from `things`);
SET @c2 = (SELECT sum(`salary`) from `dude_base`);
UPDATE `current` SET `curr_cash` = @c1 * @c2 / 100
于 2012-11-30T10:32:25.820 回答