如何使用腳本上的左連接更新表。我正在使用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