表结构CREATE TABLE `customer_apply` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `account` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `password` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `platform` tinyint(3) unsigned DEFAULT NULL COMMENT '',
  `type` tinyint(3) unsigned DEFAULT NULL COMMENT '',
  `trade_type` tinyint(3) unsigned DEFAULT NULL COMMENT '',
  `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `mobile` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `identity_id` varchar(30) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `company_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `shop_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `invitation_code` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `shop_apply_type` tinyint(3) unsigned DEFAULT '1' COMMENT '',
  `apply_reason` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `approval_status` tinyint(3) unsigned DEFAULT '1' COMMENT '',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` int(10) unsigned DEFAULT NULL COMMENT '',
  `updated_by` int(10) unsigned DEFAULT NULL COMMENT '',
  `deleted_by` int(10) unsigned DEFAULT NULL COMMENT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=62 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='';CREATE TABLE `customer_business` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `customer_id` int(10) unsigned DEFAULT NULL COMMENT '',
  `type` tinyint(3) unsigned DEFAULT NULL COMMENT '',
  `trade_type` tinyint(3) unsigned DEFAULT NULL COMMENT '',
  `name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `identity_id` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `account_name` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `company_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `level` int(10) unsigned DEFAULT NULL COMMENT '',
  `category_id` int(10) unsigned DEFAULT NULL COMMENT '',
  `platform_name` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `last_year_sales` int(10) unsigned DEFAULT NULL COMMENT '',
  `this_year_sales` int(10) unsigned DEFAULT NULL COMMENT '',
  `company_address` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `person_in_charge` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `person_in_charge_mobile` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `person_in_charge_qq` varchar(20) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `person_in_charge_mail` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `bank_name` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `bank_account` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `bank_card` varchar(50) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `tax_registration_number` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `belongs_to_seller_id` int(10) unsigned DEFAULT NULL COMMENT '',
  `belongs_to_bd_id` int(10) unsigned DEFAULT NULL COMMENT '',
  `status` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` int(10) unsigned DEFAULT NULL COMMENT '',
  `updated_by` int(10) unsigned DEFAULT NULL COMMENT '',
  `deleted_by` int(10) unsigned DEFAULT NULL COMMENT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='';CREATE TABLE `customers` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `account` varchar(40) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `password` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `mobile` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '',
  `origin` tinyint(3) unsigned DEFAULT NULL COMMENT '',
  `remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_by` int(10) unsigned DEFAULT NULL COMMENT '',
  `updated_by` int(10) unsigned DEFAULT NULL COMMENT '',
  `deleted_by` int(10) unsigned DEFAULT NULL COMMENT '',
  PRIMARY KEY (`id`),
  UNIQUE KEY `customers_mobile_unique` (`mobile`)
) ENGINE=InnoDB AUTO_INCREMENT=87 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='';
lumen项目中没有对mysql的sql_mode做任何限制,DB_STRICT_MODE没有在env文件中设置,\vendor\laravel\lumen-framework\config\database.php看到strict也是false  ,'strict'    => env('DB_STRICT_MODE', false)
数据库用的阿里云的,其中sql_mode的设置是\s
但是依旧有下面的报错信息
#26 {main} {"exception":"[object] (Illuminate\\Database\\QueryException(code: 42000): SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #17 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'user.customer_business.last_year_sales' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select `customer_apply`.`id`, `customer_apply`.`account`, `customer_apply`.`password`, `customer_apply`.`platform`, `customer_apply`.`type`, `customer_apply`.`trade_type`, `customer_apply`.`name`, `customer_apply`.`mobile`, `customer_apply`.`company_name`, `customer_apply`.`identity_id`, `customer_apply`.`approval_status`, `customer_apply`.`created_at`, `customer_apply`.`updated_at`, `customer_apply`.`created_by`, `customer_apply`.`updated_by`, `customer_apply`.`deleted_by`, `customer_business`.`last_year_sales` from `customer_apply` inner join `customers` on `customers`.`mobile` = `customer_apply`.`mobile` inner join `customer_business` on `customers`.`id` = `customer_business`.`customer_id` where `customer_apply`.`approval_status` in (1) and `customer_apply`.`platform` = 1 and `customer_apply`.`approval_status` = 1 and `customer_apply`.`trade_type` = 1 and `customer_business`.`trade_type` = 1 and `customer_apply`.`deleted_at` is null group by `customer_apply`.`id` limit 10 offset 0) at /var/www/User-DAL/vendor/illuminate/database/Connection.php:664, PDOException(code: 42000): SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #17 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'user.customer_business.last_year_sales' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by at /var/www/User-DAL/vendor/illuminate/database/Connection.php:326)
而且单独执行报错的这条sql是没问题的
 select `customer_apply`.`id`, `customer_apply`.`account`, `customer_apply`.`password`, `customer_apply`.`platform`, `customer_apply`.`type`, `customer_apply`.`trade_type`, `customer_apply`.`name`, `customer_apply`.`mobile`, `customer_apply`.`company_name`, `customer_apply`.`identity_id`, `customer_apply`.`approval_status`, `customer_apply`.`created_at`, `customer_apply`.`updated_at`, `customer_apply`.`created_by`, `customer_apply`.`updated_by`, `customer_apply`.`deleted_by`, `customer_business`.`last_year_sales` from `customer_apply` inner join `customers` on `customers`.`mobile` = `customer_apply`.`mobile` inner join `customer_business` on `customers`.`id` = `customer_business`.`customer_id` where `customer_apply`.`approval_status` in (1) and `customer_apply`.`platform` = 1 and `customer_apply`.`approval_status` = 1 and `customer_apply`.`trade_type` = 1 and `customer_business`.`trade_type` = 1 and `customer_apply`.`deleted_at` is null group by `customer_apply`.`id` limit 10 offset 0不知道为什会报这个错,虽然我已经加了额外的group by之后不报错了。

解决方案 »

  1.   

    这个是数据库的问题。
    进db设置允许groupby其它字段即可,至于哪个设置项,自己搜索一下。
    还有,你可以改sql,select的字段,显式的写明包含group by的字段
      

  2.   

    mysql 版本问题
      

  3.   

    mysql ini 添加
    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION