我写了一个这样的触发器:
CREATE TRIGGER `update_after_itemPresent` AFTER INSERT ON `bus_repair`
FOR EACH ROW begin
IF NEW.unit <> `item_present`.`unit` THEN
update item_present
set unit = unit-new.unit
where item_present.item_group_id = new.item_group_id;
END IF;
end
但是当我在 bus_repair
表中插入新行时,它给出了一个错误:
unknown table item_present in field list
知道如何解决这个问题吗?
最佳答案
将您的 UPDATE item_preset 语句移到 IF 上方和 UPDATE 内的 IF 或改写为条件。您需要先更新或选择表 item_present。
关于mysql - 在 mysql if 语句中使用来自另一个表的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12328685/