問題:
#1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this is incompatible with sql_mode=only_full_group_by
原因:
當SELECT 清單中有未包含在GROUP BY 子句中的非聚合列時,會發生此錯誤。在 MySQL 5.7.12 版本中,預設啟用 only_full_group_by SQL 模式,該模式強制執行更嚴格的分組規則。解決方案:
要解決此錯誤,您可以:1。將非聚合列新增至 GROUP BY 子句:
這可確保查詢僅傳回 GROUP BY 子句中所有欄位具有相同值的行。SELECT libelle, credit_initial, disponible_v, SUM(montant) AS montant FROM fiche, annee, type WHERE type.id_type = annee.id_type AND annee.id_annee = fiche.id_annee AND annee = YEAR(CURRENT_TIMESTAMP) GROUP BY libelle, credit_initial, disponible_v ORDER BY libelle ASC;
2。停用 only_full_group_by SQL 模式:
這允許查詢傳回 GROUP BY 子句中所有欄位可能不具有相同值的行。sudo vim /etc/mysql/conf.d/mysql.cnf
[mysqld] sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
sudo service mysql restart
以上是如何修復 MySQL'SELECT 清單的表達式不在 GROUP BY 子句中”錯誤?的詳細內容。更多資訊請關注PHP中文網其他相關文章!