Laravel 5.3: Syntax error or access violation: 1463 Non-grouping field 'distance' is used in HAVING clause

后端 未结 3 2094
别那么骄傲
别那么骄傲 2020-12-11 16:08

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.

So I have this kind of eloquent query:

相关标签:
3条回答
  • 2020-12-11 16:34

    Check in the config/database.php file in the mysql conection that the strict is false:

    'strict' => false,
    

    If is true, put in false.

    0 讨论(0)
  • 2020-12-11 16:37

    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(DB::raw("SQRT( POW((x - {$this->x}),2) + POW((y - {$this->y}),2) ) "), '<=', $distance)
    
    0 讨论(0)
  • 2020-12-11 16:49

    Try using group by clause on distance field.

      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();
    
    0 讨论(0)
提交回复
热议问题