php - 在 laravel 5.3 中按查询分组

标签 php mysql laravel mysql-error-1055

我已经触发了这个查询:

$articleList = \DB::table(config('backend.article_table'))
                ->leftjoin(config('access.users_table'), config('access.users_table') . '.id', '=', config('backend.article_table') . '.created_by')
                ->leftjoin(config('backend.article_specialization_table'), config('backend.article_specialization_table') . '.article_id', '=', config('backend.article_table') . '.id')
                ->leftjoin(config('backend.specialization_table'), config('backend.specialization_table') . '.id', '=', config('backend.article_specialization_table') . '.specialization_id')
                ->select(config('backend.article_table') . '.*', config('access.users_table') . '.name', config('access.users_table') . '.avatar', \DB::raw('group_concat(' . config('backend.specialization_table') . '.name) specialization'))
                ->whereRaw($appendWhr)
                ->whereRaw($appendPermission)
                ->groupBy(config('backend.article_table') . '.id')
                ->offset($offset)
                ->limit($pageLimit)
                ->orderBy(config('backend.article_table') . '.id', 'desc')
                ->get();

但是我得到了以下错误:

PDOException in Connection.php line 332: SQLSTATE[42000]: Syntax error or access violation 1055 'baseproject_new.articles.user_id' isn't in GROUP BY

PDOException in Connection.php line 332: SQLSTATE[42000]: Syntax error or access violation 1055 'baseproject_new.articles.user_id' isn't in GROUP BY

enter image description here

当在 mysql 中运行查询时,我得到了结果,但是当我运行页面时,我得到了错误。当我在 laravel 中使用相同的查询时,它会给我结果,但在 laravel 5.3 中我得到了这个错误。我该如何解决这个问题?

最佳答案

你只需要在config/database中将“strict”的值改为“false”即可

关于php - 在 laravel 5.3 中按查询分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41017728/

相关文章:

php - 值未通过 ajax 将 session 数组更新为 json 数组

java - JPA 与同一实体的两个单向@OneToMany 关系导致重复条目

mysql - 我如何通过 sql 和 group by keywords 获取组计数?

php - Laravel - 访问模型属性的不同方法

mysql - 拉拉维尔 5.3 : Auto Incrementing Unsigned TINYINT

Laravel 从迁移中迁移特定文件

php - 我无法接收推送通知 - 我收到响应 "Resource Id #3"

php - 在不使用表格的情况下均匀间隔多个行元素文本

php - Drupal 添加外部链接到自定义菜单

mysql - 无法在 Windows 7 上连接到本地主机 (10061) 上的 MySQL 服务器