我有两张桌子
表一:default_sellers_commissions
有:
id
value - INT
表二:marketplace_saleperpartner
有:
id
userID
commission - INT default '0.00'
commission_id
我需要的是在表marketplace_saleperpartner
中插入新行后,使用来自marketplace_saleperpartner.commission
default_sellers_commissions.value
的{{1}}更新marketplace_saleperpartner.commission_id = default_sellers_commissions.id
值。CREATE TRIGGER `marketplacedefaultcommission`
AFTER INSERT ON `marketplace_saleperpartner`
FOR EACH ROW
UPDATE marketplace_saleperpartner
SET `marketplace_saleperpartner`.`commision` = `default_sellers_commissions`.`value`
WHERE `marketplace_saleperpartner`.`comm_id` = `default_sellers_commissions`.`id`
AND `marketplace_saleperpartner`.`commision`='0.00';
所以我创建了一个触发器:
marketplace_saleperpartner.commision
P.S:
出于某种原因,我需要MySql Error: Can't update table in stored function/trigger because it is already used by statement which invoked this stored function/trigger
第一次插入值=' 0.00'
现在,我在尝试将新行插入表marketplace_saleperpartner
时收到此错误assertion
请帮忙吗?
答案 0 :(得分:1)
您可以使用BEFORE INSERT
触发器将marketplace_saleperpartner.commision
设置为value
marketplace_saleperpartner
。
CREATE TRIGGER marketplacedefaultcommission
BEFORE INSERT ON marketplace_saleperpartner
FOR EACH ROW
BEGIN
SET new.commission = (
SELECT value
FROM default_sellers_commissions
WHERE id = new.commission_id
);
END;