laravel 5.3 groupBy使用报错isn't in GROUP BY

使用的ubuntu,本地配置的apache环境,laravel 5.3使用groupBy报错

    `$list   = \DB::table('game_answer_record')->groupBy('uid')->select(\DB::raw('id, quality, uid'))->get();`

报的错误如下 :
`QueryException in Connection.php line 770:
SQLSTATE[42000]: Syntax error or access violation: 1055 'ezhenduan2.app_game_answer_record.id' isn't in GROUP BY (SQL: select id, quality, uid from app_game_answer_record group by uid)`
sql语句在mysql中执行正常

JellyBool

这个有可能是 mysql 的版本问题。

Rayle0801

服务器的mysql 5.6.34,这错误是连接服务器数据库报的错,本地的mysql是5.7.17也报错
of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘ezhenduan2.app_game_answer_record.id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select id, quality, uid from app_game_answer_record group by uid)

JellyBool

database.php :


'mysql' => [
            'driver'    => 'mysql',
            'host'      => env('DB_HOST', 'localhost'),
            'database'  => env('DB_DATABASE', 'forge'),
            'username'  => env('DB_USERNAME', 'forge'),
            'password'  => env('DB_PASSWORD', ''),
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
            'strict'    => false, // 这个选项改为 false
        ],
Rayle0801 回复 JellyBool

谢谢 JellyBool