Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Table Goods_has_Taker(order_id,good_id...)
- Table Goods (good_id, price...)
- Table OrderD (order_id, transaction_date, amount)
- CREATE DEFINER = CURRENT_USER TRIGGER `mydb`.`OrderD_BEFORE_INSERT`
- BEFORE INSERT ON `OrderD` FOR EACH ROW
- BEGIN
- DECLARE quantity Int;
- declare price FLoat;
- set new.transaction_date=NOW(),
- @quantity :=
- (select out_quantity from Goods_has_Taker
- where Goods_has_Taker.order_id=new.order_id),
- @price :=
- (select price from Goods
- Inner Join Goods_has_Taker
- On Goods.good_id=Goods_has_Taker.good_id
- Where new.order_id = Goods_has_Taker.order_id
- ),
- new.amount=@quantity*@price;
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement