我在 MySQL 5.7 中对下面的查询有疑问,但在 MySQL 5.6 中它运行良好。
每次都会出现此消息:
1055 - SELECT 列表的表达式 #6 不在 GROUP BY 子句中,并且包含
在功能上不依赖于 GROUP BY 子句中的列的非聚合列“electricity_databases.electricity_invoices.date_inserted”;这与 sql_mode=only_full_group_by 不兼容
SQL 代码:
SELECT
homes.id,
homes.homeName,
homes.city,
homes.date_registered,
ROUND(SUM(electricity_invoices.total), 2) AS TotalPrice,
DATEDIFF(NOW(), electricity_invoices.date_inserted) AS last_insert_in_days,
MAX(electricity_invoices.date_inserted) AS last_insert,
COUNT(electricity_invoices.homeID) AS countPaymentTimes,
MAX(electricity_invoices.currRead) AS currRead,
MAX(electricity_invoices.prevRead) AS prevRead,
ROUND(MAX(electricity_invoices.currRead) - MAX(electricity_invoices.prevRead), 1) AS lastComp,
customer.name
FROM homes
LEFT JOIN electricity_invoices ON
homes.id = electricity_invoices.homeID
LEFT JOIN customer ON
homes.id = customer.homeID
GROUP BY homes.id
ORDER BY homes.id