我有一個SQL查詢來計算我需要使用UPDATE語句更新其信息的確切數量。但它包含一些複雜的連接,我不確定如何在UPDATE語句中重新創建該語句。任何幫助?將SELECT語句轉換爲其對應的UPDATE語句
我的查詢是在這裏:
select distinct c.id
from implementation.tt_ngma_exclude_emails nee
join customer c on nee.util_account_id = c.util_internal_id
join customer_notification_contact cnc on cnc.customer_id = c.id
left join customer_notification_contact_audit cnca on cnca.customer_id = c.id
where cnc.changed_on = '2015-11-15 12:30:02';
的這裏的目標是在customer_notification_contact
表更新特定領域,而不是從我選擇的實施表。我想設置email
領域的數控工作臺爲NULL到處是cnc.customer_id = c.id
這裏是我的嘗試,但它似乎並沒有工作:
UPDATE customer_notification_contact cnc
(select distinct cnc.customer_id opower_customer_id
from implementation.tt_ngma_exclude_emails nee
join customer c on nee.util_account_id = c.util_internal_id
join customer_notification_contact cnc on cnc.customer_id = c.id
where cnc.changed_on = '2015-11-15 12:30:02'
) T2
SET cnc.email = NULL
WHERE cnc.customer_id = T2.opower_customer_id;
連接將保持不變。只要將'select ... from ...'改爲'update ...' –
對不起,我認爲原來的問題含糊不清。我想更新customer_notification_contact。不是implementation.tt_ngma_exclude_emails。 – Asif