2016-01-21 9 views
10

Odbieranie następujący błąd:SELECT lista nie jest w klauzuli GROUP BY i zawiera nonaggregated kolumna

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 

Uruchamiając następujące zapytanie:

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 ; 

Korzystanie z MySQL testową świecie bazę danych (http://dev.mysql.com/doc/index-other.html). Nie mam pojęcia, dlaczego tak się dzieje. Obecnie działa MYSQL 5.7.10.

Jakieś pomysły ??? : O

+1

Masz 'opcję ONLY_FULL_GROUP_BY' enabled, co usuwa luźne reguły MySQL dotyczące 'GROUP BY'. – Barmar

+0

Ustawienia domyślne dla tej opcji zostały zmienione w MySQL 5.7. – Barmar

Odpowiedz

1

country.code nie znajduje się w Twojej instrukcji group by i nie jest agregatem (zawijanym w funkcję agregującą).

http://www.w3schools.com/sql/sql_functions.asp

+0

Link nie działa, spróbuj umieścić aktualną treść w miejscu hiperłączy podczas odpowiadania. – amey

11

Jak @Brian Riley już wspomniano należy albo usunąć 1 kolumna w wybranej

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 ; 

lub dodać go do swojej grupy

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 ; 
+0

Dziękuję za to. To bardzo pomogło! – racl101

+0

lub po prostu uruchom z wiersza poleceń mysql: SET GLOBAL sql_mode = (WYBIERZ REPLACE (@@ sql_mode, 'ONLY_FULL_GROUP_BY', '')); –

Powiązane problemy