0
我試圖做一個觸發器必須做一個減法,如果order_status從0更改爲1或2.更新的order_status行中的數量值應從另一個表中的quantity_in_stock中減去。這是我試過的,但它不適合我。Mysql觸發器在2個表中進行計算?
begin
DECLARE orderQuantity INT(11);
if old.order_status = 0 and new.order_status != 0 then
select quantity into orderQuantity from `order` where id=new.id;
update product_in_stock
set quantity_in_stock = sum(quantity_in_stock - orderQuantity)
where id=1;
end if;
end
謝謝拉胡爾,生病給一個鏡頭! –
我需要添加表和東西到最後一行,對吧? –
@MacLuc,添加我最後提到的代碼,然後在減法中使用變量。 – Rahul