一个例子:
一张成绩表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门课程),这样就会出现个错误:单行子查询返回多行。
  请教各位,这个句子该怎么写?

解决方案 »

  1.   

    update t1 T set score =(select avg(score) from t1 where t1.cno = T.CNO ) where 
    cno in(select cno from t2 where tname in('JAVA','C#'));
      

  2.   

    在1楼的基础上增加点东西update t1 T set score =(select avg(score) from t1 where t1.cno = T.CNO group by t1.cno) ....
      

  3.   

    楼上两位前辈汇总。
    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#'));