2014-09-26 68 views
0

更新2表中包含2個用於匹配AS400 SQL中的鍵的字段。請幫助我處理此SQl查詢。 我試過下面的查詢,它正在工作,但想要微調。更新2表中有2個字段的表中的字段用於匹配AS400 SQL中的鍵。請幫助我使用此SQl查詢

update  color0 as a 
    set A.COL_COL1PCT = (select B.COL_COL1PCT 
          from srpua/color0919 as b 
          where A.COL_COLOR= B.COL_COLOR) 
    , A.COL_CHGDTE = 20140919 
    , a.COL_CHGUSER ='SRPUA'            
where A.COL_COLOR in (SELECT B.COL_COLOR from srpua/color0919 as b) 
+0

目前尚不清楚您期望的「微調」。你展示的是標準的。也不清楚你想從另一個表中更新'2 Fields'。您只顯示一個從另一個文件更新的字段。 – user2338816 2014-09-28 11:25:17

+0

通常,「微調」SQL實際上是爲優化器創建合適的索引來處理的。 – 2014-09-29 13:52:00

回答

1

真的沒有「微調」做......

你可能會使用一個行值表達式喜歡的替代語法;假設一個相對的,IBM v5r4(?)左右的DB2版本。

update  color0 as a 
    set (A.COL_COL1PCT,A.COL_CHGDTE, A.COL_CHGUSER) 
    = (select B.COL_COL1PCT, 20140919, 'SRPUA'  
      from srpua/color0919 as b 
     where A.COL_COLOR= B.COL_COLOR) 
where A.COL_COLOR in (SELECT B.COL_COLOR from srpua/color0919 as b) 
0

以下內容同時更新A.COL_COL1PCT和A.COL_COLOR字段。它在查爾斯的回答中做出了調整:

update color0 as a 
set (A.COL_COL1PCT, A.COL_COLOR, A.COL_CHGDTE, A.COL_CHGUSER) 
= (select B.COL_COL1PCT, B.COL_COLOR, 20140919, 'SRPUA'  
     from srpua/color0919 as b 
    where A.COL_COLOR= B.COL_COLOR) 
相關問題