Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
779 views
in Technique[技术] by (71.8m points)

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

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:

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 where status = 1 and id not in (1) having distance <= 6 order by distance asc)

I wanted to check if the ONLY_FULL_GROUP_BY mode is enabled on my server, but it isn't...

SELECT @@sql_mode NO_ENGINE_SUBSTITUTION

The same query works fine in MySQL workbench. What's going on?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

'strict' => false,

If is true, put in false.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...