说起来有点复杂。现在有两张表,a跟b,a.unid=b.a_unid
但是在a表中有字段c_field,如果c_field里存了一个a的unid,那么有该c_field的a的item就是个house item,c_field指向的item是master item
现在,要把master item对应的b table中的值cno,批量赋到house item对应的b table的cno中去
sql语言要怎么写啊?

解决方案 »

  1.   

    也不是递归,我举个直观的例子a表有两个值,a表中两个字段分别是unid,lot_unid
    a1的值:house1,master1
    a2的值:master1,nullb表也有对应的两个值,b表中字段的值a_unid,contractnob1的值:house1,null
    b2的值:master1,100现在我想把b1的contractno的值变成b2的100
    sql要怎么写呢
      

  2.   

    lot_unid 是有多个对应还是只有一次对应
    例如a1:house1, master2
    a2:master2, master1
    a3:master1, null
      

  3.   

    试试-- 方法1:
    merge into b t1
    using (select a.unid, b.contractno
            from a, b
           where a.lot_unid = b.a_unid) t2
       on (t1.a_unid = t2.unid)
     when matched then
    update set t1.contractno = t2.contractno;