-- 使用当前(子表)表某字段更新 对应行记录其他字段 (存在主子表关系) left join

Posted 廿二又

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了-- 使用当前(子表)表某字段更新 对应行记录其他字段 (存在主子表关系) left join相关的知识,希望对你有一定的参考价值。


-- 使用当前(子表)表某字段更新 对应行记录其他字段 (存在主子表关系) left join
update 
(
select a.* from ic_purchasein_b a 
left join ic_purchasein_h b on b.cgeneralhid = a.cgeneralhid
where  b.pk_org = '0001A1100000001BN4N6'and (vdef2 is not null and vdef2 <> '~')
) t

set t.nqtunitnum = (
  select nnum
    FROM (
       select cunitid --计量单位
        ,nnum  --实收数量
        ,ic_purchasein_h.vbillcode
        ,cgeneralbid
        from ic_purchasein_b ic_purchasein_b
        left join ic_purchasein_h ic_purchasein_h on ic_purchasein_h.cgeneralhid = ic_purchasein_b.cgeneralhid
        where ic_purchasein_h.pk_org = '0001A1100000001BN4N6'and (vdef2 is not null and vdef2 <> '~')

    ) b  where b.cgeneralbid = t.cgeneralbid
)




以上是关于-- 使用当前(子表)表某字段更新 对应行记录其他字段 (存在主子表关系) left join的主要内容,如果未能解决你的问题,请参考以下文章