mysql group by 报错异常解决

mysql报错及其解决方式

1、在使用group by 查询一张表的数据的时候:select date,time,max(delaytime) as delaytime,sum(delaynum) as delaynum, max(onlineCount) as onlineCount,sum(perMinuteVerify) as perMinuteVerify,auditor 
from verifyDelayLog WHERE `date` = '2016-06-29' group by time;

报错如下:
ERROR 1055 (42000): Expression #7 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'postscan.verifyDelayLog.auditor' which is not functionally dependent on columns 
in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

原因:使用  select @@sql_mode; 命令可以看到,数据库设置了 ONLY_FULL_GROUP_BY 的mode,意思就是:
对于GROUP BY聚合操作,如果在SELECT中的列,没有在GROUP BY中出现,那么这个SQL是不合法的,因为列不在GROUP BY从句中
所以对于设置了这个mode的数据库,在使用group by 的时候,就要用MAX(),SUM(),ANT_VALUE()这种聚合函数,才能完成GROUP BY 的聚合操作。
原文地址:https://www.cnblogs.com/mr-wuxiansheng/p/7918519.html