create procedure Pro_QCname_Chour_xkrs_AverScore_MaxScore @Tname_in char(20),@Cname_in char(30), @Chour_out tinyint output,@xkrs_out int output, @Aver_Score tinyint output,@Max_Score tinyint output as declare @Sum_Score int select @Chour_out=Chour,@xkrs_out=count(Sno),@Sum_Score=sum(Score),@Max_Score=max(Score) from SC,Course,Teacher,TC where Course.Cno=SC.Cno and Teacher.Tno=TC.Tno and Course.Cno=TC.Cno group by SC.Cno having Tname=@Tname_in and Cname=@Cname_in select @Aver_Score=@Sum_Score/@xkrs_out go,选择列表中的列 'Course.Chour' 无效,因为该列没有包含在聚合函数或 GROUP BY 子句中。
时间: 2024-02-13 17:05:50 浏览: 140
上机实验二——数据表定义和管理实验.doc
这个错误是因为在查询语句中没有将所有非聚合列包含在 GROUP BY 子句中。在这个例子中,Course.Chour 列没有被包含在 GROUP BY 子句中,所以会报错。你需要在查询语句中将所有非聚合列包含在 GROUP BY 子句中,例如:
```
select Course.Chour, count(SC.Sno) as xkrs, avg(SC.Score) as Aver_Score, max(SC.Score) as Max_Score
from SC,Course,Teacher,TC
where Course.Cno=SC.Cno and Teacher.Tno=TC.Tno and Course.Cno=TC.Cno
group by Course.Chour, Course.Cname, Teacher.Tname
having Teacher.Tname=@Tname_in and Course.Cname=@Cname_in
```
这个查询语句将 Course.Chour 列包含在了 GROUP BY 子句中,同时也包含了其他需要聚合的列。
阅读全文