2017-10-08 59 views
1

我想在我的第一個表「p_edw_tmp.TK_NPS_subdate」的列中插入值,並且這些值必須具有相同的標識符(subs_id = subs_id),但是我的請求會在此處插入我的請求和結果是我得到Inserto into ... select

INSERT INTO p_edw_tmp.TK_NPS_subdate (activationDate) 

SELECT b.activation_date 
FROM P_EDW_BO_UNIVERSE.DW_SUBNOS b 
WHERE p_edw_tmp.TK_NPS_subdate.subs_id=b.subs_id 

結果

survey   subno subs_id  activationdate 
date 
NULL   NULL NULL  28/03/2013 
NULL   NULL NULL  14/09/2017 
NULL   NULL NULL  11/02/2006 
NULL   NULL NULL  07/02/2007 
NULL   NULL NULL  20/04/2011 
01/07/2015 770611368 60 584 365 NULL 
01/07/2015 772682168 3 541 647 NULL 
01/07/2015 770827778 6 616 NULL 
01/07/2015 774614365 34 444 141 NULL 
01/07/2015 796997578 73 457 413 NULL 

我想造成這樣

01/07/2015 770611368 60 584 365 07/02/2007 
01/07/2015 772682168 3 541 647 20/04/2011 
+1

你想用'UPDATE'? – GurV

+0

我不明白你的問題。請重新表述這 –

回答

2

好像你想更新現有數據:

UPDATE p_edw_tmp.TK_NPS_subdate 
FROM 
(SELECT subs_id, activation_date 
    FROM P_EDW_BO_UNIVERSE.DW_SUBNOS 
) AS b 
SET activationDate = src.activationDate 
WHERE p_edw_tmp.TK_NPS_subdate.subs_id=b.subs_id 
+0

SRC指B,謝謝它的工作 –

+0

UPDATE p_edw_tmp.TK_NPS_subdate FROM (SELECT subs_id,activation_date FROM P_EDW_BO_UNIVERSE.DW_SUBNOS )爲B SET activationDate = b.activation_date WHERE p_edw_tmp.TK_NPS_subdate.subs_id = B .subs_id –

1

這是因爲您只選擇列b.activation_date並指定列(activationDate)名稱並僅插入到該列中。

您需要指定要在插入中插入的列名並選擇它們。所以,你可以查詢更改爲類似:

INSERT INTO p_edw_tmp.TK_NPS_subdate (survey,subno,subs_id,activationdate) 

SELECT b.survey,b.subno,b.subs_id,b.activation_date 
FROM P_EDW_BO_UNIVERSE.DW_SUBNOS b 
WHERE p_edw_tmp.TK_NPS_subdate.subs_id=b.subs_id