Список SELECT не находится в предложении GROUP BY и содержит неагрегированный столбец
Получение следующей ошибки:
Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'world.country.Code' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
При выполнении следующего запроса:
select countrylanguage.language, country.code, sum(country.population*countrylanguage.percentage/100)
from countrylanguage
join country on countrylanguage.countrycode = country.code
group by countrylanguage.language
order by sum(country.population*countrylanguage.percentage) desc ;
Использование мировой тестовой базы данных MySQL (http://dev.mysql.com/doc/index-other.html). Не знаю, почему это происходит. В настоящее время работает MYSQL 5.7.10.
Любые идеи???: О
Ответы
Ответ 1
Поскольку @Brian Riley уже сказал, что вы должны либо удалить 1 столбец в своем выборе
select countrylanguage.language ,sum(country.population*countrylanguage.percentage/100)
from countrylanguage
join country on countrylanguage.countrycode = country.code
group by countrylanguage.language
order by sum(country.population*countrylanguage.percentage) desc ;
или добавьте его в свою группу
select countrylanguage.language, country.code, sum(country.population*countrylanguage.percentage/100)
from countrylanguage
join country on countrylanguage.countrycode = country.code
group by countrylanguage.language, country.code
order by sum(country.population*countrylanguage.percentage) desc ;
Ответ 2
country.code
не входит в ваш оператор group by
и не является агрегатом (завернутым в агрегатную функцию).
http://www.w3schools.com/sql/sql_functions.asp