一个例子:
一张成绩表t1,有三个字段:sno,cno,score
一张课程表t2,有两个字段:cno,cname
现在要将cname为JAVA,C#的score更新为各自的平均分数。我试着写过:update t1 set score =(select avg(score) from t1 group by cno) where
cno in(select cno from t2 where tname in('JAVA','C#'));
可是这个句子明摆是不对的,(select avg(score) from t1 group by cno)返回了4行数据(假设总共有4门课程),这样就会出现个错误:单行子查询返回多行。
请教各位,这个句子该怎么写?
一张成绩表t1,有三个字段:sno,cno,score
一张课程表t2,有两个字段:cno,cname
现在要将cname为JAVA,C#的score更新为各自的平均分数。我试着写过:update t1 set score =(select avg(score) from t1 group by cno) where
cno in(select cno from t2 where tname in('JAVA','C#'));
可是这个句子明摆是不对的,(select avg(score) from t1 group by cno)返回了4行数据(假设总共有4门课程),这样就会出现个错误:单行子查询返回多行。
请教各位,这个句子该怎么写?
cno in(select cno from t2 where tname in('JAVA','C#'));
update t1 T set score =(select avg(score) from t1 where t1.cno = T.CNO group by t1.cno ) where
cno in(select cno from t2 where tname in('JAVA','C#'));