我有兩張大桌子。我們稱它們為ITEM表(1807236 條記錄)和ITEM_PROD_DUMP表(796369 條記錄)。我需要用主鍵 ( ) 匹配的第二個表的值更新表中的兩列 ( total_volume_amount, total_volume_uom) 。ITEMITEM_PROD_DUMPSYS_ITEM_ID
我為此撰寫了一個查詢,它可以作業,但僅適用于少數記錄。對于這些大量的記錄,它只是繼續運行。
誰能幫我寫一個正確和最佳的查詢。
我寫的查詢:
update item i set i.total_volume_amount = (select ipd.total_volume_amount
from item_prod_dump ipd
where i.sys_item_id = ipd.sys_item_id),
i.total_volume_uom = (select ipd.total_volume_uom
from item_prod_dump ipd
where i.sys_item_id = ipd.sys_item_id)
where exists (select ipd.total_volume_amount
from item_prod_dump ipd
where i.sys_item_id = ipd.sys_item_id);
uj5u.com熱心網友回復:
使用MERGE宣告。純粹而簡單。180 萬條記錄并不是一個“巨大”的記錄數。
merge into item t
using ( SELECT *
FROM item_prod_dump ipd ) u
on ( t.sys_item_id = u.sys_item_id )
when matched then update set t.total_volume_amount = u.total_volume_amount,
t.total_volume_uom = u.total_volume_uom;
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/439334.html
上一篇:包含連接的SQL子查詢
