2017-10-04 75 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