Php 为什么laravel查询不能返回正确的结果?
我在laravel中有这个代码,以获得即将用完的产品Php 为什么laravel查询不能返回正确的结果?,php,mysql,laravel-4,Php,Mysql,Laravel 4,我在laravel中有这个代码,以获得即将用完的产品 $productos = DB::table('productos') ->where('producto_minimo', '>=', 'producto_cantidad') ->get(); 我得到的结果如下 这不是正确的结果。而在MySql中,我通过此查询从productos中选择*得到正确的结果,其中producto_minimo>=pro
$productos = DB::table('productos')
->where('producto_minimo', '>=', 'producto_cantidad')
->get();
我得到的结果如下
这不是正确的结果。而在MySql中,我通过此查询从productos中选择*得到正确的结果,其中producto_minimo>=producto_cantidad;
更新
查询日志-DB::getQueryLog-显示了这一点
2 =>
array (size=3)
'query' => string 'select * from `productos` where `producto_minimo` >= ?' (length=54)
'bindings' =>
array (size=1)
0 => string 'producto_cantidad' (length=17)
'time' => float 1
我假设您必须使用whereRaw方法: 您的查询将比较producto_minimo列中的值与字符串“producto_cantidad” 看一看雄辩的文档: 上述查询将生成以下SQL:
我假设您必须使用whereRaw方法: 您的查询将比较producto_minimo列中的值与字符串“producto_cantidad” 看一看雄辩的文档: 上述查询将生成以下SQL:
我真的认为,实际上发布结果而不是发布图片对我们所有人来说都会更容易。我发布了,但我不能发布太多的问题代码。您是否尝试在database.php中启用debug=true,以便您可以记录实际执行的数据库查询?@giannischristofakis id 4应该是唯一的结果,但是我得到了表中的所有行。是的,第一个结果是错误的:producto_minimo=10,这比producto_cantidad=20……我真的认为,实际上发布结果而不是发布图片对我们所有人来说都会更容易。我做到了,但是我不能发布太多的问题,你是否尝试在database.php中启用debug=true,以便记录实际执行的数据库查询?@giannischristofakis id 4应该是唯一的结果,但我得到了表中的所有行。是的,第一个结果是非常错误的:producto_minimo=10,这小于producto_cantidad=20。。。
$productos = DB::table('productos')
->whereRaw('producto_minimo >= producto_cantidad')
->get();
DB::table('users')
->whereExists(function($query)
{
$query->select(DB::raw(1))
->from('orders')
->whereRaw('orders.user_id = users.id');
})
->get();
select * from users
where exists (
select 1 from orders where orders.user_id = users.id
)