表aa
aa表有
fj
xx
表bb
bb表有
xn
xx
要根据bb表的xx条件来更新aa表的fjupdate aa set aa.fj=1 where bb.ff=200
这样为什么不行
where后面一定要aa的条件吗?aa表里有xx与bb表里有xx
外键关联
如何求?
update aa set aa.fj=1 where bb.ff=200 and aa.xx=bb.xx
这样也不行

解决方案 »

  1.   

    试试:
    update   aa  s  set   s.fj=1   where exists(select 'Z' from bb t where t.xx=s.xx)
      

  2.   

    试试 update aa a,bb b set a.fj=1
    where a.xx=b.xx and b.xx=200;
      

  3.   

    update   aa  s  set   s.fj=1   where exists(select 'Z' from bb t where t.ff=200 and t.xx=s.xx)
    如果不行,那要讲一下错误提示是什么呀
      

  4.   

    update aa as a set a.fj=1 where a.xx in (select b.xx from bb as b where b.ff=200).说一下,你的ff是什么?在你的表结构说明中根本就没有提.
      

  5.   

    应该:   update   aa   a,bb   b   set   a.fj=1 
    where   a.xx=b.xx   and   b.ff=200;
      

  6.   

    学校表xx
    有:xx_m 学校码
       sbbj上报标记(1为未上报,2为已上报)

    贷款表dk
    有:xx_m 学校码
       dkxn 贷款学年

    还一张表是:dksz 当前贷款学年
    dkxn 贷款学年
    学校表的xx_m与贷款表的xx_m关联,贷款学年的格式是'2006-2007'这样的,有很多贷款学年,如2005-2006现在是要求把所有学校当前贷款学年的sbbj更新为1
      

  7.   

    update xx set xx.sbbj=1 where exists(select dkxn from dk,xx  where xx.xx_m=dk.xx_m and dkxn=(select dkxn from dksz) )
    这样子写又不行
      

  8.   

    不行你要说一下错误是什么?
    我怀疑你的语句:
    update   xx   set   xx.sbbj=1   where   exists(select   dkxn   from   dk,xx     where   xx.xx_m=dk.xx_m   and   dkxn=(select   dkxn   from   dksz)   ) 
    中的:
    select   dkxn   from   dk,xx     where   xx.xx_m=dk.xx_m   and   dkxn=(select   dkxn   from   dksz) 
    能不能运行,select   dkxn   from   dksz是单值得吗?
      

  9.   

    update       xx       set       xx.sbbj=1       where       exists(select       dkxn       from       dk,xx           where       xx.xx_m=dk.xx_m       and       dkxn=(select       dkxn       from       dksz)       )  
    可以运行select       dkxn       from       dk,xx           where       xx.xx_m=dk.xx_m       and       dkxn=(select       dkxn       from       dksz)  
    查出来的是学年信息,2006-2007,几千条记录select       dkxn       from       dksz
    是一条记录:就是当前的贷款学年:2006-2007