這是我的表:如何添加兩個值,並執行其中條件laravel雄辯
id remaining_amount additional_amount
1 200 0
2 100 -100
3 300 100
4 200 -50
我試圖讓具有remaining_amount的總和 + additional_amount行> 0 。
$result = $this->model->where('remaining_amount' + 'total' > 0)->get();
它沒有工作。然後我試着這樣:
$result = DB::table('cash')->select(DB::raw('remaining_amount+additional_amount AS total'))
->where('total','>',0)
->get();
它也行不通。
請告訴我解決這個問題的方法。
你不能在計算值的條件下執行 –
爲什麼不使用聚合方法求和 –