简体   繁体   English

Laravel 在具有“ROW_NUMBER() OVER PARTITION”的子查询中混合 GROUP 列(MIN()、MAX()、COUNT()、...)

[英]Laravel Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) on a sub query with "ROW_NUMBER() OVER PARTITION"

I know there are tons of question that includes that error, but I haven't seen one that incldues a subquery with row_numbers.我知道有很多问题都包含该错误,但我还没有看到包含带有 row_numbers 的子查询的问题。

Ok so I have this raw query which WORKS when I run directly on a database management application (I use sequel pro)好的,所以我有这个原始查询,当我直接在数据库管理应用程序上运行时它可以工作(我使用 sequel pro)

The ff info was actually taken from my previous question : ff 信息实际上取自我之前的问题

I ended up having this query我最终得到了这个查询

select * from (select *, ROW_NUMBER() OVER(PARTITION BY type ORDER BY id) AS seqnum from `example`) as `t` where `seqnum` <= 50

This query works perfectly on sequel pro (database management application)此查询在 sequel pro(数据库管理应用程序)上完美运行

but when I do (wrap it on DB::statement in laravel):但是当我这样做时(将其包装在 Laravel 中的 DB::statement 上):

DB::statement("select * from (select *, ROW_NUMBER() OVER(PARTITION BY type ORDER BY id) AS seqnum from `example`) as `t` where `seqnum` <= 50");

On Laravel I get:在 Laravel 上,我得到:

Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

Any ideas why did it failed on laravel but was ok on a database management app?任何想法为什么它在 laravel 上失败但在数据库管理应用程序上没问题?

Go to config/database.php and just change value of strict to false: Go 到 config/database.php 并将 strict 的值更改为 false:

  'strict' => false, // <= be sure that this is set to false

https://floyk.com/en/post/how-to-fix-error-group-columns-is-illegal-if-there-is-no-group-by-clause https://floyk.com/en/post/how-to-fix-error-group-columns-is-illegal-if-there-is-no-group-by-clause

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果没有GROUP BY子句,则将GROUP列(MIN(),MAX(),COUNT()等)混合在一起是非法的 - Mixing of GROUP columns (MIN(),MAX(),COUNT(),…) with no GROUP columns is illegal if there is no GROUP BY clause MySQl错误:#1140-如果没有GROUP BY子句,则没有GROUP列的GROUP列(MIN(),MAX(),COUNT(),…)混合是非法的 - MySQl Error : #1140 - Mixing of GROUP columns (MIN(),MAX(),COUNT(),…) with no GROUP columns is illegal if there is no GROUP BY clause 语法错误或访问冲突:1140 混合 GROUP 列 (MIN(),MAX(),COUNT(),...) - Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) Laravel子查询最大分组依据 - Laravel Sub Query Max of Group By Laravel:在视图上对查询进行分页 MySQL 错误 1140 Mixing of GROUP 列 - Laravel: Paginating a query on a view MySQL Error 1140 Mixing of GROUP columns 在laravel中使用mysql查询来计算行数 - Count number of row using mysql query in laravel PHP SQLSRV-查询不适用于ROW_NUMBER - PHP SQLSRV - Query Not Working with ROW_NUMBER Laravel查询最大和分组依据 - Laravel query with max and group by 在PostgreSQL中使用Windows函数row_number()OVER() - Using the Windows Function row_number() OVER () in PostgreSQL 矩阵中每一行的最小值和最大值 - Min and max number from every row in matrix
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM