mysql报错1140 In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregate

数据库语句报In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'szmz_zhbz_gov.b.cremation_time'; this is incompatible with sql_mode=only_full_group_by 

经查阅资料得知,在MySQL5.7版本之后对group by进行了优化。默认启动改进之后的版本启动了ONLY_FULL_GROUP_BY模式。

即ONLY_FULL_GROUP_BY是MySQL数据库提供的一个sql_mode,通过这个sql_mode来保证SQL语句“分组求最值”合法性的检查。这种模式采用了与Oracle、DB2等数据库的处理方式。即不允许select target list中出现语义不明确的列。

解决方法:

mysql报错1140 In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregate

只要有聚合函数sum(),count(),max(),avg()等函数就需要用到group by

相关文章:

  • 2022-12-23
  • 2021-06-14
  • 2021-05-05
  • 2021-08-22
  • 2022-01-11
  • 2022-12-23
  • 2022-02-24
  • 2021-08-02
猜你喜欢
  • 2022-12-23
  • 2021-11-12
  • 2021-07-16
  • 2021-05-18
  • 2021-11-04
  • 2021-05-08
  • 2021-04-24
相关资源
相似解决方案