这里我有这样的表
目的地:
|id_dest | price |
| 1 |2000 |
| 2 |100 |
| 3 |1000 |
项:
|id_item | weight | id_dest |total(weight*destination.price) |
| 1 | 3 | 2 |
触发器应该
|id_item | weight | id_dest |sum(weight*destination.price) total |
| 1 | 3 | 2 |300
查询触发器应该如何?
答案 0 :(得分:0)
CREATE TRIGGER trigger_name
BEFORE INSERT ON item
FOR EACH ROW
BEGIN
UPDATE item
SET total = (SELECT d.price *, NEW.weight
FROM destination d
WHERE d.id_dest = NEW.id_dest)
WHERE id_item = NEW.id_item;
END