我已经在数据库中联接了三个表,现在我想在区域表中独特地选择列区域中的值,并计算在联接表中重复的每个区域的计数。 以下代码是我如何加入城市,商店和区域表
$product = Producttext::where('id',$id)->first();
//test and check that you have it $product->SupplierID
$suplierproduct = Company::select('id', 'CompanyName')->where('id',$product->SupplierID)
->first();
答案 0 :(得分:0)
尝试一下:
$zones= Store::join('cities as c','store.city_id','=','c.id')
->join('zones as z','c.zone_id','=','z.id')
->select(DB::raw('count(z.id) as z_count, z.*'))
->groupBy('z.id')
->get();