Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre
錯內容
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre
原因分析
mysql 5.7預設啟用ONLY_FULL_GROUP_BY特性,即:對於GROUP BY聚合操作,如果在SELECT中的列,沒有在GROUP BY中出現,那麼這個SQL是不合法的,因為列不在GROUP BY從句中,也就是說查出來的列必須在group by後面出現否則就會報錯,或者這個欄位出現在聚合函式裡面。
解決方法
在mysql的配置檔案的最後強制設定sql_mode,把預設的ONLY_FULL_GROUP_BY去掉。
預設的sql_mode:(java專案fhadmin.cn)
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
修改mysql的配置檔案,在檔案最底部加上:
[mysqld]
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
重新啟動mysql後生效。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31558068/viewspace-2868539/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql報錯:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggreMySqlExpressAI
- list is not in GROUP BY clause and contains nonaggre的問題AI
- [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated cExpressAI
- [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains 的問題 MySQLExpressAIMySql
- mysql主給備賦予許可權時報錯,MySQL [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clauseMySqlExpress
- C# 有關List<T>的Contains與Equals方法C#AI
- SQL改寫的方法,select group by sumSQL
- List中對比Contains, Exists, Any之間的優缺點AI
- Linq使用Group By 1
- MySQL SELECT list is not in...MySQL關閉嚴格模式MySql模式
- JavaScript contains()JavaScriptAI
- Oracle Model ClauseOracle
- DML_The OUTPUT Clause
- Oracle SQL Model ClauseOracleSQL
- B組group1:A - Artwork
- mysql select欄位別名 不可以在select 或者where中使用 但是group by 與order by可以使用MySql
- 通過建立動態型別 動態構建Expression Select表示式來控制Property可見性型別Express
- [LintCode/LeetCode] Contains Duplicate IIILeetCodeAI
- mybatis註解Select查詢List,返回有物件個數,但是為nullMyBatis物件Null
- 4.3.2.2.1 The SEED FILE_NAME_CONVERT Clause
- leetcode 219. Contains Duplicate IILeetCodeAI
- Leetcode 10 Regular Expression MatchingLeetCodeExpress
- 【shell 】syntax error in conditional expressionErrorExpress
- find: paths must precede expression:Express
- Study for Go ! Chapter two - ExpressionGoAPTExpress
- [SwiftUI 100天] Bucket List - part1SwiftUI
- alter tablespace ts_name autoextend_clause
- WPF custom control contains datagrid,listbox,imageAI
- [LeetCode] 282. Expression Add OperatorsLeetCodeExpress
- Syntax error, unrecognized expression: li[value=]ErrorZedExpress
- condition expression returns non-BooleanExpressBoolean
- 瞭解C#的ExpressionC#Express
- 動態拼接表示式——ExpressionExpress
- select 下拉框用 Select select = new Select (element) 方法失敗
- std::sort 錯誤"Expression : invalid operator <"Express
- [LeetCode] 2134. Minimum Swaps to Group All 1s Together IILeetCode
- You can‘t specify target table ‘Person‘ for update in FROM clause
- [20221123]19cDBA_EXPRESSION_STATISTICS查詢expression_text中字串帶雙引號的問題Express字串