Mysql group by the rules to meet the requirements of:

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: HTTPS: //blog.csdn.net/u011066470/article/details/97291377
----------------
Disclaimer: This article is CSDN bloggers' health and peace alive. " the original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/u011066470/article/details/97291377

GROUP BY satisfy rules:

Select all fields except field aggregate functions, you must appear in a GROUP BY.

例如:SELECT  name,age,max(salary) FROM  t_employee  GROUP BY  name,age

salary field can not appear in a GROUP BY

only_full_group_by role
ONLY_FULL_GROUP_BY is a MySQL sql_mode provided by this sql_mode to provide SQL statements to check the legality of the GROUP BY, when sql_mode non ONLY_FULL_GROUP_BY semantics of MySQL. A select statement, MySQL allowing expression target list is output in addition to the expression or function group by aggregate column, the value of this expression may become undefined after a group by operation.

As for the semantic restrictions are more stringent than databases such as SQLServer, Oracle, PostgreSql not support select semantics ambiguous column appears in the target list, such statements in these databases would be an error, so from the MySQL 5.7 release began fixes this semantics, it is what we call ONLY_FULL_GROUP_BY semantics, such as viewing the default MySQL 5.7 sql_mode as follows:

mysql> select @@global.sql_mode;

Guess you like

Origin www.cnblogs.com/kukai/p/11444046.html