如何使用脚本上的左连接更新表。我正在使用DB2数据库。左连接更新表
我创建了一个SELECT语句,它的工作原理:
**
select t1.estrcd as "transaction code",
t1.espyno as "payer",
t1.escuno as "customer no",
t1.escino as "invoice no",
t1.esvono as "voucher no",
t1.escuam as "foreign currency amount",
COALESCE(t2."received_amount",0) as "received amount",
t1.escuam + COALESCE(t2."received_amount",0) as "outstanding amount"
from m3edbedu.fsledg t1 left join
(select espyno, escino, sum(escuam) as "received_amount" from m3edbedu.fsledg
where estrcd = 20 group by espyno, escino) as t2 on
t2.espyno = t1.espyno and t2.escino = t1.escino
where t1.esreco = 0 and t1.estrcd = 10 and (t1.escuam + COALESCE(t2."received_amount",0)) = 0
order by t1.espyno, t1.escino, t1.estrcd;
**
但现在他们要我更新表和t1.esreco设置为9。我尝试使用下面的脚本来更新,但我得到一个错误。
update m3edbedu.fsledg t1 LEFT JOIN(select espyno, escino, sum(escuam) as "received_amount"
from m3edbedu.fsledg
where estrcd = 20
group by espyno, escino) as t2
on t2.espyno = t1.espyno and t2.escino = t1.escino set t1.esreco = 9 where t1.esreco = 0 and t1.estrcd = 10 and (t1.escuam + COALESCE(t2."received_amount",0)) = 0 order by t1.espyno, t1.escino, t1.estrcd;1;
Error: SQL0199 - Keyword LEFT not expected. Valid tokens: SET. (State:37000, Native Code: FFFFFF39) Error: SQL0104 - Token 1 was not valid. Valid tokens: (CL END GET SET CALL DROP FREE HOLD LOCK OPEN WITH ALTER BEGIN. (State:37000, Native Code: FFFFFF98)
我希望有人能帮助我。
在此先感谢。 :)
感谢您的快速回复,但我仍然有同样的错误:错误:SQL0199 - 关键字从不预期。有效令牌:在哪里跳过。 (状态:37000,本机代码:FFFFFF39) 错误:SQL0104 - 令牌1无效。有效令牌:(CL END GET SET CALL DROP FREE HOLD LOCK WITH ALTER BEGIN。(状态:37000,本机代码:FFFFFF98) – Christian 2012-03-08 18:57:18
应该已经读过你正在使用的数据库引擎,DB2显然不喜欢使用FROM子句更新声明,我会尽快给你一个更新的响应 – SPFiredrake 2012-03-08 19:04:59