Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何将一个查询结果(通过变量)发送到另一个查询_Mysql_Database_Laravel_Laravel 5.5_Laravel Query Builder - Fatal编程技术网

Mysql 如何将一个查询结果(通过变量)发送到另一个查询

Mysql 如何将一个查询结果(通过变量)发送到另一个查询,mysql,database,laravel,laravel-5.5,laravel-query-builder,Mysql,Database,Laravel,Laravel 5.5,Laravel Query Builder,我想要的是将子变量的结果包含到另一个查询中 $sub = DB::table('chef_food_ethics')-> select(DB::raw('count(id) as fCount')) ->where('chef_food_ethics.food_ethic_id', '=','food_ethic_managers.food_ethic_id') ->toSql(); 有可能把它包括在内吗 $r = DB::table('food_ethic_ma

我想要的是将子变量的结果包含到另一个查询中

 $sub = DB::table('chef_food_ethics')->
 select(DB::raw('count(id) as fCount'))
 ->where('chef_food_ethics.food_ethic_id',
 '=','food_ethic_managers.food_ethic_id')
 ->toSql();
有可能把它包括在内吗

 $r = DB::table('food_ethic_managers')where
 ('food_ethic_managers.manager_id','=',$id)
 ->leftJoin('staff','food_ethic_managers.food_ethic_id'
  ,'=','staff.id')
 ->leftJoin('regions','staff.region_id','=','regions.id')
 ->with($sub)
 ->get();

我尝试了$r=DB::table('food'u-etrich'u-managers'),其中('food'u-etrich'u-managers.manager'id','=',$id)->leftJoin('staff','food'etrich'managers.food'u-etrich'id','=','regions.id')->union('sub get();但这给了我**基数冲突:1222使用的SELECT语句有不同的列数**这可能是一个联合。确保$sub和$r的列数相同same@JackPoint或者没有其他方法??laravel雄辩的ORM您可以做到。我如何使用ORM进行嵌套查询@普拉蒂克梅塔