1

我将开始在 phpmyadmin 中使用 mysql。

我的桌子:

表格1:

primary key = id1;
cash1 = thing I want to pick from that table;

表2:

primary key = id2;

cash2 = thing I want to pick from that table;

表3:

foreign key1 = id1;
foreign key2 = id2;
cash3 = thing I want to make;

所以,我想做:

Update (or insert into?) cash3 = cash1*cash2/100 when UPDATE ON cash1 or cash2.

尝试了很多东西,似乎没有任何工作......

4

1 回答 1

1

您的触发器(每个 table1 和 table2 都需要一个)应如下所示:

create trigger cash1 on table1 for insert, update
   Select @c1=sum(cash) from table1
   Select @c2=sum(cash) from table2
   Update table3 set cash=@c1*@c2/100
end

注意:以上只是伪代码,因为我不熟悉 mysql 语法。

该触发器的作用是,当您更改 table1 中的金额时,它会从 table1 和 table2 中选择金额并计算 table3 的金额并更新它。

您需要另一个触发器,它在 table2 上执行相同的操作。

在不知道您的表设置(列名)的情况下很难使用给您一个像样的代码示例

希望这可以帮助。

于 2012-11-30T08:12:17.883 回答