如何在laravel雄辩中添加两列值并执行where条件 [英] How to add two columns value and perform where condition in laravel eloquent
本文介绍了如何在laravel雄辩中添加两列值并执行where条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的桌子:
id remaining_amount additional_amount
1 200 0
2 100 -100
3 300 100
4 200 -50
我正在尝试获取总计为 remaining_amount + additional_amount > 0的行.
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();
它也不起作用.
请告诉我解决方法.
推荐答案
使用whereRaw
尝试此操作:
$query = DB::table('cash')
->whereRaw("(remaining_amount+additional_amount AS total) > 0)")
->get();
这篇关于如何在laravel雄辩中添加两列值并执行where条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文