升级到 mysql 5.7.21 后:与 sql_mode=only_full_group_by 不兼容
After upgrading to mysql 5.7.21: incompatible with sql_mode=only_full_group_by
从 5.7.20
升级到 mysql 5.7.21
后,出现错误
SELECT ac.vatcode_id,ac.vatcode_type,v.name vatcode_name,v.txt vatcode_txt
FROM `accounting` ac
LEFT JOIN `vatcode` v ON v.id=ac.vatcode_id
WHERE ac.account_id=300479 && ac.vatcode_id>=0 && ac.time BETWEEN 1514764800 AND 1546214400 && ac.block_id=4431
GROUP BY ac.vatcode_id
#1055 - Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'dynaccount.ac.vatcode_type' which is
not functionally dependent on columns in GROUP BY clause; this is
incompatible with sql_mode=only_full_group_by
# show variables;
sql_mode
STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
您的查询无效。您告诉 DBMS:"per ac.vatcode_id
give me the ac.vatcode_type
"。并且 DBMS 告诉您没有 the ac.vatcode_type
每个 ac.vatcode_id
;可以有多个不同的。那你想要哪个?最大值?然后做这个MAX(ac.vatcode_type)
。最小值?然后制作MIN(ac.vatcode_type)
。你不在乎哪个?然后使这个 ANY_VALUE(ac.vatcode_type)
.
您的新 MySQL 版本更加严格,希望您编写符合 SQL 标准的有效查询。这是好事。
从 5.7.20
升级到 mysql 5.7.21
后,出现错误
SELECT ac.vatcode_id,ac.vatcode_type,v.name vatcode_name,v.txt vatcode_txt
FROM `accounting` ac
LEFT JOIN `vatcode` v ON v.id=ac.vatcode_id
WHERE ac.account_id=300479 && ac.vatcode_id>=0 && ac.time BETWEEN 1514764800 AND 1546214400 && ac.block_id=4431
GROUP BY ac.vatcode_id
#1055 - Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'dynaccount.ac.vatcode_type' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
# show variables;
sql_mode
STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
您的查询无效。您告诉 DBMS:"per ac.vatcode_id
give me the ac.vatcode_type
"。并且 DBMS 告诉您没有 the ac.vatcode_type
每个 ac.vatcode_id
;可以有多个不同的。那你想要哪个?最大值?然后做这个MAX(ac.vatcode_type)
。最小值?然后制作MIN(ac.vatcode_type)
。你不在乎哪个?然后使这个 ANY_VALUE(ac.vatcode_type)
.
您的新 MySQL 版本更加严格,希望您编写符合 SQL 标准的有效查询。这是好事。