Laravel SQLSTATE[42000]:语法错误或访问冲突:1055

Mur*_*aya 4 php mysql sql-server laravel laravel-5.3

我正在尝试使用 laravel 5.3 构建查询。但当我进行此查询时,我收到此错误。

错误:

SQLSTATE[42000]: 语法错误或访问冲突: 1055 'laravel.location.locationDate' 不在 GROUP BY 中 (SQL: select count(*), locationDate from where location= tagCode24930 and xLocation> -1 and xLocation< 194 and yLocation> 60 and yLocation< 190 和created_at> 2017-03-09 00:00:01 和created_at< 2017-03-09 23:59:59 按 DATE(locationDate)、hour(locationDate)) 分组

顺便说一句,如果我复制查询并尝试在 sql 中运行它,它就可以工作。但我只是将引号添加到created_at,例如'2017-03-09 00:00:01'

这是我的代码..

$zoneTime = DB::table('location')
                            ->select(DB::raw('count(*), locationDate'))
                            ->where('tagCode', $tagCode)
                            ->where('xLocation', '>', $workingZone->x1)
                            ->where('xLocation', '<', $workingZone->x3)
                            ->where('yLocation', '>', $workingZone->y3)
                            ->where('yLocation', '<', $workingZone->y1)
                            ->where('created_at', '>', $startDate)
                            ->where('created_at', '<', $endDate)
                            ->groupBy(DB::raw('DATE(locationDate)'))
                            ->groupBy(DB::raw('hour(locationDate)'))
                            ->get();
Run Code Online (Sandbox Code Playgroud)

Mur*_*aya 5

我在配置/数据库中更改了 strict = false 并且它起作用了。

  • 这是一个临时解决方案,您可能应该更新您的查询。 (3认同)