Php Laravel SQLSTATE[42000]:语法错误或访问冲突:1055
我正在尝试用laravel 5.3构建一个查询。但是当我做这个查询时,我得到了这个错误 错误: SQLSTATE[42000]:语法错误或访问冲突:1055“laravel.location.locationDate”不在分组依据中(SQL:select count(*),位置日期从Php Laravel SQLSTATE[42000]:语法错误或访问冲突:1055,php,mysql,sql-server,laravel,laravel-5.3,Php,Mysql,Sql Server,Laravel,Laravel 5.3,我正在尝试用laravel 5.3构建一个查询。但是当我做这个查询时,我得到了这个错误 错误: SQLSTATE[42000]:语法错误或访问冲突:1055“laravel.location.locationDate”不在分组依据中(SQL:select count(*),位置日期从location开始,其中tagCode=24930和xLocation-1和xLocation60和yLocation其中('tagCode',$tagCode) ->其中('xLocation','>',$wor
location
开始,其中tagCode
=24930和xLocation
-1和xLocation
<194和yLocation
>60和yLocation
<190和创建时间2017-03-09 00:00:01和创建时间
<2017-03-09 23:59:59按日期分组(位置日期),小时(地点日期)
顺便说一句,如果我复制查询并尝试在sql中运行它,它会正常工作。但我只是在“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();
$zoneTime=DB::table('location')
->选择(DB::raw('count(*),locationDate'))
->其中('tagCode',$tagCode)
->其中('xLocation','>',$workingZone->x1)
->其中('xLocation','',$workingZone->y3)
->其中('Y位置',''$startDate)
->其中('created_at','您必须在group by子句中使用相同的字段,如下所示:
$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) as locationDate'))
->groupBy(DB::raw('hour(locationDate)'))
->get();
$zoneTime=DB::table('location')
->选择(DB::raw('count(*),locationDate'))
->其中('tagCode',$tagCode)
->其中('xLocation','>',$workingZone->x1)
->其中('xLocation','',$workingZone->y3)
->其中('Y位置',''$startDate)
->其中('created_at','我在config/database中更改了strict=false,并且它已工作。这是一个临时解决方案,您可能应该更新查询。