select s.s_id,s_name,avg(sc2.s_score) from student s join (select sc1.s_id,count(sc1.s_id) cc from score sc1 where sc1.s_score<60 group by sc1.s_id having cc>=2) t on s.s_id =t.s_id join score sc2 on s.s_id =sc2.s_id; 报SQL 错误 [10025] [42000]: Error while compiling statement: FAILED: SemanticException [Error 10025]: Line 1:7 Expression not in GROUP BY key 's_id'帮我修改一下
时间: 2024-03-18 19:42:38 浏览: 82
BIOS_R02.06.0007_package_Romley_Platforms.zip
根据错误信息,查询语句中的表达式 's_id' 不在 GROUP BY key 中,因此需要将其添加到 GROUP BY 子句中。下面是修改后的 SQL 查询语句:
```
SELECT s.s_id, s.s_name, AVG(sc2.s_score)
FROM student s
JOIN (
SELECT sc1.s_id, COUNT(sc1.s_id) cc
FROM score sc1
WHERE sc1.s_score < 60
GROUP BY sc1.s_id
HAVING cc >= 2
) t ON s.s_id = t.s_id
JOIN score sc2 ON s.s_id = sc2.s_id
GROUP BY s.s_id, s.s_name;
```
修改后,查询语句会按照 s_id 和 s_name 进行分组,从而解决了错误信息中提到的问题。
阅读全文