MySql 错误:In aggregated query without GROUP BY, expression #1 of SELECT list contains....

select AVG(s_score),student.s_id from student natural left outer join score
WHERE s_score is null

运行上述SQL查询时,提示错误信息:

In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'school.student.s_id'; this is incompatible with sql_mode=only_full_group_by

这个错误的中文翻译:

在不使用group by 子句的聚合查询中,Select列表中的第一个表达式包含了非聚合的列‘school.student.s_id’;当sql_mode为only_full_group_by时,是不能出现这种情况的。

错误信息里面说student.s_id 这一列是非聚合的,可能指的是没使用聚合函数,果不其然,当我在student.s_id前面加上max的时候,就可以正常执行了

也就是说,mysql的sql_mode是only_full_group_by的时候,在不使用group by 并且select后面出现聚集函数的话,那么所有被select的都应该是聚集函数,否则就会报错

你可能感兴趣的:(SQL)