在新的tupple插入到detail_of_sale表中之后,我想用触发器更新我的产品表。
我已经搜索了这个问题,并尝试了几种解决方法,但我无法解决。
这是我的桌子。
detail_of_sale(detailID,saleID,productID,quantity ...)
product(productID,stock ...);
Create Trigger editQuantity AFTER INSERT ON detail_of_sale
BEGIN
Update product join detail_of_sale on
detail_of_sale.productID=product.productID set stock=stock-(Select quantity
from detail_of_sale where saleID=new.SaleID);
END
答案 0 :(得分:0)
您不希望使用join
,而只引用new
表:
Update product
set stock = stock - new.quantity
where productID = new.productID;
答案 1 :(得分:0)
尝试一下:
<?php
use Illuminate\Support\Facades\DB;
$my_id = \Session::get('user_id');
$messagesSentByMe = DB::table('messages')->where('sender_id', '=', $my_id)->get();
$messagesReceivedByMe = DB::table('messages')->where('receiver_id', '=', $my_id)->get();
//And the thing I wanna do is: extract similar id from the first messages, then the second messages and then from both the messages so that, I can have the user_id whom I have sent or received messages with.
?>