update A set Status=1 WHERE exists (select * FROM (select a.Code FROM A a,B b WHERE rownum<=5 and a.ProdCode in ('013') and a.SNo=b.ID a.Status=0 and a.LevelNo=1 order by a.Code ) b WHERE A.Code=b.Code)
这个SQL我再9i上运行大约用了6分钟,可是select a.Code FROM A a,B b WHERE rownum<=5 and a.ProdCode in ('013') and a.SNo=b.ID a.Status=0 and a.LevelNo=1 order by a.Code 这个查询语句才不到1秒就运行完了其实我想要的效果就是更新表A中CODE字段的值为下面 SQL 查询出来数据,然后更新Status为1,不知道该怎么写更快点??还有不能用IN,我用in测试过,更慢select a.Code FROM A a,B b WHERE rownum<=5 and a.ProdCode in ('013') and a.SNo=b.ID a.Status=0 and a.LevelNo=1 order by a.Code 

解决方案 »

  1.   

    是不是这个意思?
    update A set Status=1 WHERE exists 
    (select count(1) FROM B b WHERE A.Code=b.Code)
    WHERE rownum<=5 and a.ProdCode in ('013') and a.Status=0 and a.LevelNo=1;
      

  2.   

    update A set Status=1 WHERE exists 
    (select count(1) FROM B b WHERE A.Code=b.Code)
    and rownum<=5 and a.ProdCode in ('013') and a.Status=0 and a.LevelNo=1;
      

  3.   


    select * FROM (select a.Code FROM A a,B b WHERE rownum<=5 and a.ProdCode in ('013') and a.SNo=b.ID a.Status=0 and a.LevelNo=1 order by a.Code ) b WHERE A.Code=b.Code
    好像只有b表,没有A表啊
      

  4.   

    update A set Status=1 WHERE exists 
    (select a.Code FROM B b WHERE A.Code=b.Code)
    WHERE rownum<=5 and a.ProdCode ='013' and a.Status=0 and a.LevelNo=1;