select country.continent,round(avg(city.population),0) as c
from city,country
where city.countrycode = country.code;
我使用了此查询,但我收到此错误
第1行的错误1140(42000):在没有GROUP BY的聚合查询中,SELECT列表的表达式#1包含非聚合列' run_2sryibds0p4.country.continent&#39 ;;这与sql_mode = only_full_group_by
不兼容
请帮助我找到正确的解决方案和解释。
答案 0 :(得分:1)
您只能使用AVG
:
GROUP BY
SELECT country.continent, ROUND(AVG(city.population), 0) AS c
FROM city,country
WHERE city.countrycode = country.code
GROUP BY country.continent;
有关GROUP BY
和汇总函数(如AVG
)的更多信息:
答案 1 :(得分: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