This is my table:
id remaining_amount additional_amount
1 200 0
2 100 -100
3 300 100
4 200 -50
I'm trying to get the rows which have a sum of remaining_amount + additional_amount > 0 .
$result = $this->model->where('remaining_amount' + 'total' > 0)->get();
it didn't work. Then I tried like this:
$result = DB::table('cash')->select(DB::raw('remaining_amount+additional_amount AS total'))
->where('total','>',0)
->get();
It doesn't work either.
Please show me the way to solve this.
Try this using
whereRaw
:You can not perform where condition on calculated value. Try using filter from laravel collection to get the desired output.
Performing filter
Got it. Thanks
I think you sohuld use aggregate method to sum as
Hope it will work for you