按不工作分组 - Laravel
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41571271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Group by not working - Laravel
提问by Parth Vora
I'm not able to run this simple query in Laravel 5.3
我无法在 Laravel 5.3 中运行这个简单的查询
$top_performers = DB::table('pom_votes')
->groupBy('performer_id')
->get();
It gives me:
它给了我:
SQLSTATE[42000]: Syntax error or access violation: 1055 'assessment_system.pom_votes.id' isn't in GROUP BY (SQL: select * from `pom_votes` group by `performer_id`)
However if I copy raw query from the error and fire directly in PhpMyAdmin, it works fine.
但是,如果我从错误中复制原始查询并直接在 PhpMyAdmin 中触发,它工作正常。
I have already checked this:
我已经检查过这个:
https://laravel.com/docs/5.3/queries#ordering-grouping-limit-and-offset
https://laravel.com/docs/5.3/queries#ordering-grouping-limit-and-offset
Any help would be appricaited.
任何帮助将被appricaited。
Thanks,
谢谢,
Parth Vora
帕斯沃拉
回答by Md.Jewel Mia
Edit your applications's database config file config/database.php
编辑应用程序的数据库配置文件 config/database.php
In mysql
array, set strict => false
to disable MySQL's strict mode
在mysql
数组中,设置strict => false
为禁用 MySQL 的严格模式
回答by Gabriele Ciech
Maybe your issue is due to the fact that you are using a MySQL server vith version 5.7.5+. From this version on the way GROUP BY
works is changed since they make it behave in order to be SQL99 compliant (where in previous versions it was not).
也许您的问题是由于您使用的是版本 5.7.5+ 的 MySQL 服务器。从这个版本开始,GROUP BY
工作方式发生了变化,因为它们使它的行为符合 SQL99(在以前的版本中不是这样)。
Try to do a full group by or change the configuration of your MySQL server.
尝试做一个完整的组或更改您的 MySQL 服务器的配置。
Linkto official MySQL doc where full GROUP BY
is explanined
链接到完整GROUP BY
解释的官方 MySQL 文档
回答by Hasib Kamal
Go to config/database.php
转到 config/database.php
Update strict value false.
更新严格值 false。
return [
'connections' => [
'mysql' => [
'strict' => false
]
]
]
回答by Md.Nazmul Hossain
Modify your database.php file from config/database.php 'strict' => true
to 'strict' => false
将您的 database.php 文件从 config/database.php 修改'strict' => true
为'strict' => false
'mysql' => [
'strict' => true
],
回答by Suraj Vaghela
Edit your applications's database config file config/database.php
编辑应用程序的数据库配置文件 config/database.php
In mysql array, set strict => false to disable MySQL's strict mod
在 mysql 数组中,设置 strict => false 以禁用 MySQL 的严格模式
or
或者
sudo nano /etc/mysql/mysql.cnf
须藤纳米 /etc/mysql/mysql.cnf
[mysqld] sql_mode = NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[mysqld] sql_mode = NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
回答by App
If you false strict mode then you can't use other strict functionality to fix this error Go to the Illuminate\Database\Connectors\MySqlConnector.phpand change function like below:
如果您使用 false 严格模式,则不能使用其他严格功能来修复此错误转到Illuminate\Database\Connectors\MySqlConnector.php并更改如下功能:
protected function strictMode() {
return "set session
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY
_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'";
}
replace function with this.
用这个替换函数。