0

我在这个请求上收到了 MYSQL 5.7 的错误。如何解决此错误?

#1055 - SELECT 列表的表达式 #3 不在 GROUP BY 子句中,并且包含非聚合列“test.c.customers_group_id”,它在功能上不依赖于 GROUP BY 子句中的列;这与 sql_mode=only_full_group_by 不兼容

select  SQL_CALC_FOUND_ROWS  c.customers_firstname, 
                             c.customers_lastname, 
                             c.customers_group_id,
                             sum(op.products_quantity * op.final_price) as ordersum 
from customers c,
     orders_products op,
     orders o
where c.customers_id = o.customers_id 
and o.orders_id = op.orders_id 
group by c.customers_firstname, 
         c.customers_lastname 
order by ordersum DESC
4

2 回答 2

4

也包括c.customers_group_id在 group by 子句中

于 2016-05-28T02:44:46.870 回答
2

你错过c.customers_group_idGROUP BY条款。

您可以使用ANSI模式代替旧式逗号分隔的表格列表模式。 JOIN

以下代码适用于您的情况:

SELECT  SQL_CALC_FOUND_ROWS  c.customers_firstname, 
                             c.customers_lastname, 
                             c.customers_group_id,
                             sum(op.products_quantity * op.final_price) as ordersum 
FROM customers c
JOIN orders o ON o.customers_id = c.customers_id 
JOIN orders_products op ON op.orders_id = o.orders_id
GROUP BY c.customers_firstname, 
         c.customers_lastname,
         c.customers_group_id -- you missed this
ORDER BY ordersum DESC
于 2016-05-28T02:58:07.350 回答