Laravel 5.3:语法错误或访问冲突:1463 HAVING 子句中使用了非分组字段“距离”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39053335/
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
Laravel 5.3: Syntax error or access violation: 1463 Non-grouping field 'distance' is used in HAVING clause
提问by user3343366
This error came up after moving the whole source to the 5.3 version, and I'm scratching my head for over two hours now.
在将整个源代码移动到 5.3 版本后出现了这个错误,我现在挠了两个多小时。
So I have this kind of eloquent query:
所以我有这种雄辩的查询:
POI::select('*', DB::raw("SQRT( POW((x - {$this->x}),2) + POW((y - {$this->y}),2) ) AS distance"))
->where('status', Config::get('app.poi_state.enabled'))
->whereNotIn('id', $excludePOIList)
->having('distance', '<=', $distance)
->orderBy('distance')->get();
It worked find before upgrade now it throws:
它在升级之前找到它现在抛出:
Syntax error or access violation: 1463 Non-grouping field 'distance' is used in HAVING clause (SQL: select *, SQRT( POW((x - 860.0000),2) + POW((y - 105.0000),2) ) AS distance from
poi
wherestatus
= 1 andid
not in (1) havingdistance
<= 6 order bydistance
asc)
语法错误或访问冲突:1463 非分组字段“距离”用于 HAVING 子句(SQL:select *, SQRT( POW((x - 860.0000),2) + POW((y - 105.0000),2) ) AS距
poi
wherestatus
= 1id
且不在 (1) 中的距离具有distance
<= 6 以distance
asc排序)
I wanted to check if the ONLY_FULL_GROUP_BY mode is enabled on my server, but it isn't...
我想检查我的服务器上是否启用了 ONLY_FULL_GROUP_BY 模式,但它不是...
SELECT @@sql_mode NO_ENGINE_SUBSTITUTION
SELECT @@sql_mode NO_ENGINE_SUBSTITUTION
The same query works fine in MySQL workbench. What's going on?
相同的查询在 MySQL 工作台中运行良好。这是怎么回事?
回答by rebduvid
Check in the config/database.php file in the mysql conection that the strict is false:
在mysql连接中的config/database.php文件中检查strict为false:
'strict' => false,
If is true, put in false.
如果为真,则输入假。
回答by Hamza Dairywala
Try using group by clause on distance field.
尝试在距离字段上使用 group by 子句。
POI::select('*', DB::raw("SQRT( POW((x - {$this->x}),2) + POW((y - {$this->y}),2) ) AS distance"))
->where('status', Config::get('app.poi_state.enabled'))
->whereNotIn('id', $excludePOIList)
->groupBy('distance')
->having('distance', '<=', $distance)
->orderBy('distance')->get();
回答by Paul Spiegel
I don't know why you get that error after the upgrade but not before. However you can move the distance condition into WHERE clause:
我不知道为什么您在升级之后而不是之前会出现该错误。但是,您可以将距离条件移动到 WHERE 子句中:
->where(DB::raw("SQRT( POW((x - {$this->x}),2) + POW((y - {$this->y}),2) ) "), '<=', $distance)