求SQL语句(91分)

N

Nstar

Unregistered / Unconfirmed
GUEST, unregistred user!
A表:
ID cnt1 cnt2
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0

B表
ID cnt1 cnt2
1 2 4
3 34 10
5 43 98
目标:
将B表中的cnt1,cnt2更新到A表中,当然B表的ID和A表的ID要对应
求此SQL语句?
 
update a set cnt1=(select cnt1 from b where (a.id=b.id)),
cnt2=(select cnt2 from b where (a.id=b.id)) where
where a.id in (select id from b)
用楼下的最好
 
UPDATE A
SET A.cnt1 =B.cnt1,A.cnt2=B.cnt2 from A,B
WHERE A.id=B.id
 
UPDATE A SET (cnt1,cnt2)=(SELECT cnt1 FROM B WHERE A.ID=B.ID,
SELECT cnt2 FROM B WHERE A.ID=B.ID)

 
我是在ORACLE环境下,
上面的各语句提示有误..
 
UPDATE report.Temp1 A SET A.cnt1=(SELECT B.cnt1 FROM report.temp2 B WHERE A.ID=B.ID),
A.cnt2=(SELECT C.cnt2 FROM report.temp2 C WHERE A.ID=C.ID);

这样就可以了
 
oracle 的话可以这样写的:
UPDATE report.Temp1 A A.cnt1 A.Cot2=(SELECT B.cnt1,B.cot2 FROM report.temp2 B WHERE A.ID=B.ID)

括号要不要记不清了
注意:没有“Set”的

 
同意楼上Nstar的写法。
 
顶部