将整个源码移到5.3版本后出现了这个错误,我现在已经抓了两个多小时了。
所以我有这种雄辩的问题:
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();
它在升级之前找到了它现在抛出:
语法错误或访问冲突:1463非分组字段&#39;距离&#39; 用于HAVING子句(SQL:select *,SQRT(POW((x - 860.0000),2)+ POW((y - 105.0000),2))AS与
poi
的距离status
= 1和id
不在(1)distance
<= 6个订单distance
asc)
我想检查我的服务器上是否启用了ONLY_FULL_GROUP_BY模式,但它不是......
SELECT @@ sql_mode NO_ENGINE_SUBSTITUTION
同样的查询在MySQL工作台中运行良好。 发生了什么事?
答案 0 :(得分:41)
检查mysql连接中的config / database.php文件,其中strict为false:
'strict' => false,
如果属实,请输入false。
答案 1 :(得分:0)
尝试在距离场上使用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();
答案 2 :(得分:0)
我不知道你为什么在升级之后得到那个错误但不是之前。但是,您可以将距离条件移动到WHERE子句中:
->where(DB::raw("SQRT( POW((x - {$this->x}),2) + POW((y - {$this->y}),2) ) "), '<=', $distance)