-- 表1.BBB与表2.CCC为关联字段,根据关联字段从表2查出N条记录,取第二条记录Update表1.AAA字段
-- 此SQL运行至where b.CCC = 表1.BBB 报错,无法识别表1.BBB。
update 表1
set 表1.AAA =
(select b2.DDD
from (select b.*, rownum as brn
from 表2 b
where b.CCC = 表1.BBB
and rownum < 3) b2
where b2.brn > 1);
怎么实现?
多谢!
分享到:
------解决方案-------------------- merge into 表1 t1
using (select ccc, ddd
from (select ccc, ddd, rownum rn from 表2 where rownum < 3)
where rn > 1) t2
on (t1.bbb = t2.ccc)
when matched then
update set t1.aaa = t2.ddd; ------解决方案--------------------