MySQL-条令:SQLSTATE[42000]:语法错误或访问冲突:选择列表的1055表达式#1不在GROUP BY子句中,包含
我正在尝试编写这个MySQL查询 理论上MySQL-条令:SQLSTATE[42000]:语法错误或访问冲突:选择列表的1055表达式#1不在GROUP BY子句中,包含,mysql,symfony,doctrine,Mysql,Symfony,Doctrine,我正在尝试编写这个MySQL查询 理论上 return $this ->createQueryBuilder('offer') ->select('offer.id') ->innerJoin('offer.course', 'course') ->innerJoin('offer.tutor', 'user') ->innerJoin('user.city', 'city') ->groupBy('offer.course')
return $this
->createQueryBuilder('offer')
->select('offer.id')
->innerJoin('offer.course', 'course')
->innerJoin('offer.tutor', 'user')
->innerJoin('user.city', 'city')
->groupBy('offer.course')
->orderBy('offer.score', 'DESC')
->getQuery();
并返回此错误:
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column
可以帮我解决吗?请阅读本手册中的更多内容: 问题是,在使用GROUPBY子句时,SELECT列需要被取消。
因此,在SELECT查询中,您应该使用MAX()SUM()ANY_VALUE()-这样的函数,即使只启用了_GROUP_BY(参见mysql手册),也可以执行查询。删除整个
GROUP BY offer.course_id
代码行。如果真的需要,可以添加DISTINCT。我认为可能是sql_模式,如其他响应中所述:SELECT中的所有字段也必须在GROUPBY中列出。最近MySQL服务器版本有这个要求。@user3760296嘿,谢谢!此解决方案适用于我:)
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column