2017-10-04 77 views
-2
select country.continent,round(avg(city.population),0) as c 
from city,country 
where city.countrycode = country.code; 

我已經使用這個查詢,但我得到這個錯誤錯誤1140我的查詢

ERROR 1140(42000)位於第1行:在彙總查詢,而GROUP BY,SELECT表達#1列表包含非聚集列'run_2sryibds0p4.country.continent';這是不符合sql_mode = only_full_group_by

請幫助我正確的解決方案和解釋請。

+1

[閱讀手冊](https://dev.mysql.com/doc/refman/5.7/en/group-by-functions.html) – waka

+0

一點幫助請用正確的查詢 –

回答

1
SELECT country.continent,round(avg(city.population),0) as c 
FROM city.country 
WHERE city.countrycode = country.code 
GROUP BY 1 

聚合列需要按非聚合列進行分組 - 在這種情況下,應該按country.continent對人口的四捨五入平均值進行分組。

看看這裏的更多信息 https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html