How to resolve SELECT list is not in GROUP BY clause and contains nonaggregated?

kurama picture kurama · May 28, 2016 · Viewed 16.4k times · Source

I am getting an error with MYSQL 5.7 on this request. How to resolve this error ?

#1055 - Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'test.c.customers_group_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with 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

Answer

b1n0ys picture b1n0ys · May 28, 2016

include c.customers_group_id also in the group by clause