[英]Laravel : Getting Single value from the database using pluck
大家好我使用Laravel,我想從數據庫中使用單個值pluck
,對該問題的查詢必須寫在Laravel方式不正常的sql.so如何寫在Laravel這個sql查詢? 我希望能夠使用AS
來更改列名和SUM
。實際上,我想要做的就是從total_quantity
列中獲取值,以執行我必須使用total_quantity
操作。 任何想法如何編寫該查詢?
提前致謝。
$PhysicalStock=DB::select("select sum(quantity) as `total_quantity` from InOutProducts where productID=$productID and InAndOut=1;")->pluck('total_quantity');
DB::table('InOutProducts')->selectRaw('SUM(quantity) as total_quantity')->where('productId', '=', $productID)->where('InAndOut', '=', 1)->pluck('total_quantity');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.