已知A:id name age address postcode
B:id name age address postcode
要求 把B的age大于30的address, postcode更新到A的address,postcode中,id关联如果用oracle怎么写?用MYsql怎么写?谢谢!!!
B:id name age address postcode
要求 把B的age大于30的address, postcode更新到A的address,postcode中,id关联如果用oracle怎么写?用MYsql怎么写?谢谢!!!
where exists (select 1 from b where a.id = b.id and b.age > 30);这是oracle的
SQL> select * from a; ID NAME AGE ADDRESS POSTCODE
---------- -------------------- ---------- -------------------- ----------
1 wh 10 sh 200000
2 wp 12 sh 200000
3 wr 17 sh 200000SQL> select * from b; ID NAME AGE ADDRESS POSTCODE
---------- -------------------- ---------- -------------------- ----------
2 wp 35 bj 100000
1 wh 45 bj 100000SQL> update a set (address,postcode) = (select address,postcode from b where a.i
d=b.id and b.age>30) where exists (select 1 from b where a.id=b.id and b.age>30)
;2 rows updated.SQL> select * from a; ID NAME AGE ADDRESS POSTCODE
---------- -------------------- ---------- -------------------- ----------
1 wh 10 bj 100000
2 wp 12 bj 100000
3 wr 17 sh 200000SQL>
update a
set (a.address, a.postcode) = (select b.address, b.postcode
from b
where a.id = b.id
and b.age > 30)
where exists (
select 1
from b
where a.id = b.id
and b.age > 30)
where exists (select 1 from b where a.id = b.id and b.age > 30);