一个SQL不能实现,作存储过程实现吧!
DECLARE
  RD STU1%ROWTYPE;
  AAA NUMBER;
CURSOR My_Cur IS
      SELECT DISTINCT no,score 
      FROM stu1 
      WHERE score > 0;
BEGINOPEN My_Cur;
LOOP
FETCH My_Cur INTO RD;
IF My_Cur%NOTFOUND THEN
    EXIT;
END IF;
SELECT COUNT(*) INTO AAA FROM STU2 WHERE NO = RD.NO;
IF AAA > 0 THEN
  UPDATE STU2
  SET SCORE = RD.SCORE
  WHERE NO = RE.NO;
ELSE
  INSERT INTO STU2("NO","SCORE") VALUES(RD.NO,RD.SCORE);
END IF;
END;

解决方案 »

  1.   

    update stu1 a set a.score=(select b.score from stu2 b where 
    a.no=b.no and a.score>0)
      

  2.   

    update stu1 a set a.score=(select b.score from stu2 b where 
    a.no=b.no and a.score>0)
    where a.no in(select no from stu2)
      

  3.   

    已经解决了,谢谢。用一个SQL就可以完成。采用的方法和xu_guanghui类似,只不过最后用的是exists不是用的in,因为in的效率我觉得没有exists高。