programing

SELECT 목록이 GROUP BY 절에 없으며 집계되지 않은 열을 포함합니다.

jooyons 2023. 9. 17. 13:03
반응형

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을 실행 중입니다.

무슨 생각 있어요?? :O

@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 ;

country.code당신 안에 없습니다.group byaggregate 함수에 포함된 aggregate가 아닙니다.

https://www.w3schools.com/sql/sql_ref_sqlserver.asp

언급URL : https://stackoverflow.com/questions/34913281/select-list-is-not-in-group-by-clause-and-contains-nonaggregated-column

반응형