2017-10-10 107 views
0

我需要連接兩個具有相同ID值但記錄數不同的表。 以下是我有:加入具有相同關鍵變量但具有不同記錄數的表

enter image description here

enter image description here

enter image description here

enter image description here

這裏是我的語法:

select a.id, 
    a.event_a, 
    a.occur_a, 
    a.site_a, 
    b.event_b, 
    b.site_b 

from table_1 a 

full outer join table_2 b 

on a.id=b.id; 
+0

標籤您與您正在使用的數據庫的問題。 –

回答

0

您似乎想要對兩個表中的大多數列進行獨立排序。

這應該做你想要什麼:

select a.id, a.event_a, a.occur_a, a.site_a, 
     b.event_b, b.site_b 
from (select a.*, row_number() over (partition by id order by id) as seqnum 
     from table_1 a 
    ) a full outer join 
    (select b.*, row_number() over (partition by id order by id) as seqnum 
     from table_2 b 
    ) b 
    on a.id = b.id; 
相關問題