环境:Server version: 5.7.27-0 ubuntu 18.04.1 (Ubuntu)

执行分组语句:select * from pet group by owner;时报错:

mysql分组报错Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

mysql>show global variables; 会发现sql_mode的值确实为only_full_group_by

mysql分组报错Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

only_full_group_by表示select字段要存在于被分组的字段中,当然聚合函数count,avg,sum,min,max是没问题的。

解决办法:修改全局变量值和会话变量值,命令行输入

 set session sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FFOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
 set global sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FFOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

 

相关文章:

  • 2022-01-01
  • 2022-12-23
  • 2021-04-25
  • 2022-01-11
  • 2022-12-23
  • 2021-07-21
  • 2022-01-03
  • 2022-12-23
猜你喜欢
  • 2021-08-22
  • 2021-09-20
  • 2022-02-22
  • 2021-11-19
相关资源
相似解决方案