用表B中的 net_amount 字段 更新表A中 net_amout 的数据.两表的关联关系是B.quote_oid = A.oidA与B表的关系是1:nB表中取值的条件是  line_num 为最小的一条,并且status不等于40参考数据如下:A: oid   net_amout
    1         100B: oid    quote_oid  line_num    status   net_amout
    100   1                  1                40         101
    101    1                 2                10         102
    103    1                  3                10        103最终我们得到的结果应该为A: OID  NET_AMOUNT
     1             102

解决方案 »

  1.   


    merge into a
    using (select b.quote_oid,
                  b.net_amout,
                  row_number() over(partition by b.quote_oid order by line_num) rn
             from b
            where b.status <> 40) t
    on (a.id = t.quote_oid and t.rn = 1)
    when matched then
      update set a. net_amount = t.net_amout;
      

  2.   


    为什么要sql92的,,oracle特有的不行?
      

  3.   

    quote_oid + line_num + status 
    是否唯一?update a
       set net_amount =
            (select net_amount
               from b
              where b.quote_oid = a.oid
                and status <> 40
                and line_num = (select min(line_num)
                                  from b c
                                 where c.quoto_oid = a.oid
                                   and status <> 40))