従業員の給与を更新する必要がある新しいトリガーを作成しました。テーブル支払いから2つの値(現金と月)を受け取り、それらを「how_much_to_pay」列に分割します。
トピックを見ました: MySQLトリガーは、トリガーが割り当てられている同じテーブルの行を更新できません。推奨される回避策は?
しかし、1つのテーブルからしか使用せず、問題なく「新しい」ものを配置できるため、役に立ちませんでした。
これが私のトリガーです:
create trigger pay_out before insert on `payment_out`
for each row
then
UPDATE `payment_out` o
INNER JOIN payment p ON p.id_1 = o.id_1 AND o.id2 = p.id2
SET o.`how_much_to_pay` = p.cash / p.months;
end;
$$
表は次のとおりです。
table payment_out
id1
id2
how_much_to_pay
table payment
id1
id2
cash
months
そしてエラー自体:
1442 - Can't update table payment_out in stored function/trigger because it is already used by statement which invoked this stored function/trigger.