[英]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.