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 的聚合操作。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM