请看下图
我需要在操作后Ongoing_Portfolio
自动更新的地方编写触发器。Ongoing_Fees
Insert
该Portfolio.Other_Fee
是一个百分比,而Ongoing_Fees.Other_Fee = Ongoing_Portfolio.Cash_Value * Portfolio.Other_Fee
。
请注意idPortfolio
所有3个表格中的。这里发生的是用户插入的数据进入后Ongoing_Portfolio
,它会扫描相关的Portfolio
使用idPortfolio
。然后,它Other_Fee
从相关的投资组合中获取并将数据插入Ongoing_Fees中。
以下是我编写的触发器,但是我无法编写insert方法来执行Other_Fee
。
CREATE TRIGGER `Ongoing_Portfolio_AINS` AFTER INSERT ON `Ongoing_Portfolio` FOR EACH ROW
INSERT INTO Ongoing_Fees (idPortfolio,Other_Fee)
VALUES
(New.idPortfolio, )
如何完成此触发器?
例子:
Portfolio.idPortfolio = 1
Portfolio.Other_Fee = 10%
现在我将数据插入 Ongoing_Portfolio
Ongoing_Portfolio.idPortfolio = 1
Ongoing_Portfolio.Cash_Value = 1000
现在,trigger
已触发,因此Ongoing_Fees中的数据应为
Ongoing_Fees.idPortfolio = 1
Ongoing_Fees.Other_Fee = 100
这是您所需要的吗?
INSERT INTO Ongoing_Fees (idPortfolio,Other_Fee)
select New.idPortfolio, p.other_fee
from Portfolio p
where p.idPortfolio = New.idPortfolio;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句