douxi4414 2016-04-01 12:33
浏览 137

在laravel查询构建器中不能使用Groupby查询

I am using the query below:

$data = DB::table('developers')
->select('iDeveloperId', 'vFirstName', 'vLastName', 'iGroupId')
->groupBy('vFirstName')
->get();

But I am getting an error like:

Warning: Creating default object from empty value in /var/www/html/laravel_demo/query_builder/db_config.php on line 40

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'hbmp_hims.developers.iDeveloperId' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by' in /var/www/html/laravel_demo/query_builder/illuminate/vendor/illuminate/database/Connection.php:333 Stack trace: #0 /var/www/html/laravel_demo/query_builder/illuminate/vendor/illuminate/database/Connection.php(333): PDO->prepare('select `iDevelo...') #1 /var/www/html/laravel_demo/query_builder/illuminate/vendor/illuminate/database/Connection.php(662): Illuminate\Database\Connection->Illuminate\Database\{closure}(Object(Illuminate\Database\MySqlConnection), 'select `iDevelo...', Array) #2 /var/www/html/laravel_demo/query_builder/illuminate/vendor/illuminate/database/Connection.php(629): Illuminate\Database\Connection->runQueryCallback('select `iDevelo...', Array, O in /var/www/html/laravel_demo/query_builder/illuminate/vendor/illuminate/database/Connection.php on line 669

What is the mistake I have done.

Note : it works when iDeveloperId is used in the place of vFirstName

Thanks in advance ...

  • 写回答

2条回答 默认 最新

  • duanchu2607 2016-04-01 12:41
    关注

    Try disable Full group by in your MySQL database.

    SET sql_mode = ''
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大