mysql使用group by分组时出现错误ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and

问题:

1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘cmp-31161029.t1.user_name’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by, Time: 0.000000s

查询sql_mode模式设置:

select @@global.sql_mode

结果:

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

解决方案:去除 ONLY_FULL_GROUP_BY重新 设置sql_mode

set @@global.sql_mode =’STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’

 

posted @ 2021-02-23 15:39  人生苦短,知足常乐!  阅读(340)  评论(0编辑  收藏  举报