作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
收到以下错误:
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 ;
关于mysql - SELECT 列表不在 GROUP BY 子句中并且包含非聚合列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34913281/
我是一名优秀的程序员,十分优秀!