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;
$$

テーブル「things」には次のものがあります。

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 に答える