我在此请求中遇到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
答案 0 :(得分:1)
也在group by子句中包含c.customers_group_id
答案 1 :(得分:1)
您在c.customers_group_id
子句中错过了GROUP 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