mysql--navicat--運行SQL時提示出錯信息-1055 - Expression #1 of ORDER BY clause is not in GROUP BYt

出錯提示

[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

應對方式

win+r
cmd
mysql -u root -p
mysql> set @@global.sql_mode='NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
Query OK, 0 rows affected, 1 warning (0.02 sec)

設置完成之後,建議重啓數據庫服務器和從新鏈接數據庫,再作數據庫操做mysql

具體參考

具體還能夠參考這份更詳細的描述web

緣由分析參考:

SQL的grop by 語法爲,
select 選取分組中的列+聚合函數 from 表名稱 group by 分組的列
從語法格式來看,是先有分組,再肯定檢索的列,檢索的列只能在參加分組的列中選。sql

因此問題中的,group by 後的 a,b,c是先肯定的。select後的a,b,c纔是能夠變的。即數據庫

如下語句都是正確的:服務器

select a,b,c from table_name group by a,b,c,d;
select a,b from table_name group by a,b,c;
select a,max(a) from table_name group by a,b,c;
1
2
3
如下語句則是錯誤的:svg

select a,b,c from table_name group by a,b;
select a,b,c from table_name group by a;
1
2
而由於MySQL的強大,它兼容了這個錯誤!!!
可是在DOS是不能的。因此出現了DOS下報錯,而在MySQL中可以查找的狀況(其實這個查找的結果是不對的)。

原文:https://blog.csdn.net/qq_26525215/article/details/52139296函數