Sql 具有双条目的Laravel雄辩查询,分组不起作用

Sql 具有双条目的Laravel雄辩查询,分组不起作用,sql,laravel,percona,heidisql,Sql,Laravel,Percona,Heidisql,我在Laravel-6.x中构建了一个查询,但是得到了重复的条目 公共职能部门 { $catArr=['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42

我在Laravel-6.x中构建了一个查询,但是得到了重复的条目

公共职能部门 { $catArr=['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','44','45']; $platformArr=['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15']; $regionArr=['1','2','3','4','5','6','7']; $languageArr=['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26']; 退货产品::加入'category\u Product'、'category\u Product.Product\u id'、'='、'products.id' ->加入'product_region'、'product_region.product_id'、'='、'products.id' ->加入'language_product'、'language_product.product_id'、'='、'products.id' ->其中'category_product.category_id',$catar ->其中“产品.平台id”,$platformArr ->其中'product_region.region_id',$regionArr ->其中'language_product.language_id',$languageArr ->groupBy'products.id' ->分页18; } 这是一个类似的SQL语句

SELECT * from `products` inner join `category_product` on `category_product`.`product_id` = `products`.`id` inner join `product_region` on `product_region`.`product_id` = `products`.`id` inner join `language_product` on `language_product`.`product_id` = `products`.`id` where `category_product`.`category_id` IN (1,2,3,4,5,6,7,8,9) and `products`.`platform_id` IN (10) and `product_region`.`region_id` IN (1,2,3,4,5,6,7) and `language_product`.`language_id` IN (26) LIMIT 20
我想我必须加上分组。但HeidiSQL返回一个错误:

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'shopdb.products.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

有什么解决方案吗?

因为这是mysql中sql模式=仅\u full\u group\u by的问题

关于sql\u模式有几种模式

尝试更改您的sql\u模式

在本地设置 设置为全局 或更改my.cnf文件:

在[mysqld]和[mysql]下面添加这一行

然后重新启动mysql

你的代码还有一个问题。不要从所有这些表中选择所有字段,这需要花费时间,最后一个表的id将覆盖上一个id。选择您想要的字段。如果名称重复,请使用另一个名称

->groupBy'products.id' ->选择RAW'products.*,类别\u product.id作为cp\u id' ->分页18; 使用任意值 也可以对列使用任意_值:

->groupBy'products.id' ->选择raw'ANY\u VALUEproducts.id,…,category\u product.id作为cp\u id' ->分页18; 禁用严格模式 也可以禁用config/database.php的严格模式

“mysql”=>[ “驱动程序”=>“mysql”, 'host'=>env'DB_host','127.0.0.1', ... “严格”=>错误, ],
您是否尝试过选择DISTINCT*?或者只是更改您的sql\u模式非常感谢!我从putty编辑mysql服务器上的sql_模式。我删除了“无自动创建用户”。>>set@@sql\u mode='STRICT\u TRANS\u TABLES,在\u DATE中没有\u ZERO\u,没有\u ZERO\u DATE,错误\u为\u除以\u ZERO,没有\u引擎\u替换'@Maaaxi看起来还可以。重要的是,只删除所有的组,你可以试试。这只是本地命令。@Maaaxi在运行该命令之前,您可以输入SELECT@@GLOBAL.sql\u mode;或选择@@SESSION.sql_模式;看看它原来是什么。
set sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
set @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
SET sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';