[Use has been resolved Mysql group by mistake

Mysql Version: 8.0.15

win10,64 bit

When the query data found that the following error code

1 select num, COUNT(course)
2 from student join score on(num = cnum)
3 GROUP BY num

Tip error:

ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause 
and contains nonaggregated column 'test.user.user_id' which is not 
functionally dependent on columns  in GROUP BY clause; this is 
incompatible with sql_mode=only_full_group_by

So Baidu identify the reasons, the original MySQL 5.7.5 and above function is dependent detection. If ONLY_FULL_GROUP_BY SQL mode is enabled (default), MySQL will refuse to select a list of query conditions or ORDER BY HAVING a list of references to non-aggregate column in the GROUP BY clause is neither named nor on their functionality. (Prior to 5.7.5, MySQL does not detect functional dependencies, ONLY_FULL_GROUP_BY is not enabled by default.)

So obviously, or else simply enable ONLY_FULL_GROUP_BY on it, but read a lot of online methods will not work, although the steps are the same, then suddenly thought, copying errors, will not be the same database (or configuration) caused error it, then use their own local parameters to modify it a success!

First, check your sql_model parameters:

1 select @@global.sql_mode;

I check out the result :( note, and not necessarily the same as the Internet, according to their own, whichever)

1 ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

Can be found, there is "ONLY_FULL_GROUP_BY" This is a basic die, so reset sql_model.

1 set @@global.sql_mode='
2 STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

In other words, the value of re-setting, simply "ONLY_FULL_GROUP_BY" deleted, set for the remaining finger on it , the blind use of online tutorials, there will be some error parameters unavailable.

Guess you like

Origin www.cnblogs.com/hjhsblogs/p/11079356.html