How to Solve MySQL version 5.7+ Group by group error

MySQL-this is incompatible with sql_mode=only_full_group_By error resolution

1. Principle level
this error occurs in MySQL version 5.7 and above:

   The default sql configuration for mysql 5.7 is: sql_mode="ONLY_FULL_GROUP_BY", which strictly enforces the "SQL92 standard".

   When upgrading from 5.6 to 5.7, most of them choose to adjust sql_mode to make it consistent with 5.6 in order to be as compatible as possible with the program.

2. SQL level

    In sql execution, the cause appears.

    Simply put: the output is called target list, which is the field followed by select, and a place group by column, which is

    group by followed by the field. Because the ONLY_FULL_GROUP_BY setting is turned on, so if a field is not in the target list 

    and group by fields, or the value of the aggregation function, then this sql query is considered illegal by mysql and will report an error.

Translated with www.DeepL.com/Translator (free version)

1. View the statement of SQL_mode is as follows

select @@GLOBAL.sql_mode;

Second, the solution – (recommended solution two)
① solution one: sql statement temporarily modify sql_mode
set @@GLOBAL.sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Question.

          After restarting the mysql database service, ONLY_FULL_GROUP_BY will still appear.

② Solution 2: perfect solution.

To modify the MySQL configuration file, add SQL manually_ Mode is mandatory. Only is not required_ FULL_ GROUP_ By attribute,
VI/etc/my. CNF
Add or modify configuration file:
sql_mode =‘STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISIN_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’

Restart the MySQL service and solve it successfully.

	service mysqld restart

Read More: