我正在尝试使用jobseeker_id进行分组,现在我想在查询中选择更多列,这是我的查询......
$jobseekers =DB::table('calllogs')
->select(DB::raw('count(*) as user_count,jobseeker_id'))
->where('jobseeker_id', '<>', 1)
->whereNotNull('type_of_call')
->groupBy('jobseeker_id')
->get();
calllogs表中有很多列,如id,jobseeker_id,type_of_call,status,call_reason等...
上面的查询只给我user_count和jobseeker_id。我想添加像user_count,jobseeker_id,type_of_call,status,call_reason等mroe列...
我试图像
一样添加$jobseekers =DB::table('calllogs')
->select(DB::raw('count(*) as user_count,jobseeker_id,type_of_call,status,call_reason'))
->where('jobseeker_id', '<>', 1)
->whereNotNull('type_of_call')
->groupBy('jobseeker_id')
->get();
dd($jobseekers);
Anyhelps非常感谢。
答案 0 :(得分:1)
所有非聚合列必须出现在group by子句中 -
select(DB::raw('count(*) as user_count,jobseeker_id,type_of_call,status,call_reason'))
->where('jobseeker_id', '<>', 1)
->whereNotNull('type_of_call')
->groupBy('jobseeker_id','type_of_call','status','call_reason')