“Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘workflow.s.id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by”
今天偶然間出現了上面的一個錯誤,提示說查詢的字段不在group by的子句中,因爲sql_mode是only_full_group_by。
查看mysql本地的sql_mode:show variables like ‘sql_mode’;
確實第一個是only_full_group_by,這個模式說明對於GROUP BY聚合操作,如果在SELECT中的列,沒有在GROUP BY中出現,那麼將認爲這個SQL是不合法的,因爲列不在GROUP BY從句中。
查看mybatis的xml文件,找到對應sql
問題就是出在查詢的s.*這個地方,仔細一想,如果group by content,一個content對應多條數據,那麼這個select s.*到底是要展示哪一條的數據呢?所以說就不允許select的列沒有出現在group by的子句中。
這樣就不會報錯了,哎呀,粗心!
作者:程序員阿坤
來源:CSDN
原文:https://blog.csdn.net/kkkun_joe/article/details/80180710
版權聲明:本文爲博主原創文章,轉載請附上博文鏈接!