Laravel SQLSTATE[42000]:语法错误或访问冲突:1055
Laravel SQLSTATE[42000]: Syntax error or access violation: 1055
我正在尝试使用 laravel 5.3 构建查询。但是当我进行此查询时出现此错误。
错误:
SQLSTATE[42000]: Syntax error or access violation: 1055 'laravel.location.locationDate' isn't in GROUP BY (SQL: select count(*), locationDate from location
where tagCode
= 24930 and xLocation
> -1 and xLocation
< 194 and yLocation
> 60 and yLocation
< 190 and created_at
> 2017-03-09 00:00:01 and created_at
< 2017-03-09 23:59:59 group by 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();
您必须像这样在 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();
我在 config/database 中更改了 strict = false,它起作用了。
我正在尝试使用 laravel 5.3 构建查询。但是当我进行此查询时出现此错误。
错误:
SQLSTATE[42000]: Syntax error or access violation: 1055 'laravel.location.locationDate' isn't in GROUP BY (SQL: select count(*), locationDate from
location
wheretagCode
= 24930 andxLocation
> -1 andxLocation
< 194 andyLocation
> 60 andyLocation
< 190 andcreated_at
> 2017-03-09 00:00:01 andcreated_at
< 2017-03-09 23:59:59 group by 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();
您必须像这样在 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();
我在 config/database 中更改了 strict = false,它起作用了。