2013-03-06 150 views
-1

目標:
使用來自表a和b的數據加載目標表c。如何使Critera進行數據遷移

問題:
我有兩個表,a和b需要遷移到相同的表c。

需要一次加載一張表。當加載到表c時,表格a的標準需要定義最接近訪問1的標準,並且對於表b,訪問最多爲2.

問題是:
你如何制定標準表c?

爲表C要求的結果:

table c 
---------- 
number access gender 
-------------------- 
1  1  2 
1  2  2 
2  2  2 
3  1  1 
4  2  1 
5  1  2 
5  2  2 

table a 
---------- 
number access gender 
-------------------- 
1  1  2 
2  1  2 
3  1  1 
4  1  1 
5  1  2 


table b 
---------- 
number access gender 
-------------------- 
1  2  2 
2  2  2 
3  2  1 
4  2  1 
5  2  2 


table c 
---------- 
number access gender 
-------------------- 
1  1  null 
1  2  null 
2  2  null 
3  1  null 
4  2  null 
5  1  null 
5  2  null 

回答

0

我想我明白你正在嘗試做的,請嘗試使用一對夫婦的MERGE語句,像這樣:

MERGE c AS target 
USING a AS source 
ON (target.number = source.number, target.access = source.access) 
WHEN MATCHED THEN 
UPDATE SET target.gender = source.gender 
WHEN NOT MATCHED BY target THEN 
INSERT (number, access, gender) 
VALUES (source.number, source.access, source.gender) 

MERGE c AS target 
USING b AS source 
ON (target.number = source.number, target.access = source.access) 
WHEN MATCHED THEN 
UPDATE SET target.gender = source.gender 
WHEN NOT MATCHED BY target THEN 
INSERT (number, access, gender) 
VALUES (source.number, source.access, source.gender) 
相關問題