我想做的是联接下表并按术语ID对其进行分组,但似乎查询的SELECT部分出现错误。谁能帮我解决问题?
public function getSponsor()
{
$sponsor = DB::table('sponsors')
->join('terms', 'terms.id', '=', 'sponsors.term_id')
->join('committees', 'committees.id', '=', 'terms.committee_id')
->join('persons', 'persons.id', '=', 'sponsors.person_id')
->select('sponsors.term_id as sponsor_term_id', 'terms.id as term_id', 'terms.term', 'persons.person_name', 'persons.id as person_id', 'committees.committee_name')
->groupBy('terms.id')
->get();
return $sponsor;
}
这是错误
SQLSTATE [42000]:语法错误或访问冲突:1055表达式#4 SELECT列表的内容不在GROUP BY子句中,并且包含未聚合的 列“ cdorts.persons.person_name”,在功能上不起作用 取决于GROUP BY子句中的列;这与 sql_mode = only_full_group_by(SQL:选择
sponsors
。term_id
作为sponsor_term_id
,terms
。id
为term_id
,terms
。term
,persons
。person_name
,persons
。id
为person_id
,committees
。committee_name
来自sponsors
内部联接terms
terms
。id
=sponsors
。term_id
内部联接committees
committees
。id
=terms
。committee_id
内部联接persons
persons
。id
=sponsors
。person_id
由terms
分组。id
)