MySQL查询出现的错误
SELECT list is not in GROUP BY clause and contains nonaggregated column ‘test.s.c_id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
比如以下查询:
查询平均成绩大于等于60分的同学的学生编号和学生姓名和平均成绩
SELECT s.*,AVG(s.s_score)
from score s,student
where student.s_id = s.s_id
GROUP BY s.s_id
HAVING AVG(s.s_score)>=60
出错的原因是显示的字段无法在分组查询后显示,逻辑不通。
所以要根据分组后的关联关系显示字段
改成:
**select student.s_id,student.s_name,AVG(s.s_score)**
from score s,student
where student.s_id = s.s_id
GROUP BY s.s_id
HAVING AVG(s.s_score)>=60