Laravel查询生成器:联接表并按ID分组

时间:2020-03-16 10:39:51

标签: mysql laravel-6

我想做的是联接下表并按术语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:选择sponsorsterm_id作为 sponsor_term_idtermsidterm_idtermstermpersonsperson_namepersonsidperson_idcommitteescommittee_name来自sponsors内部联接terms termsid = sponsorsterm_id内部联接committees committeesid = termscommittee_id内部联接persons personsid = sponsorsperson_idterms分组。id

0 个答案:

没有答案