2017-10-10 130 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; 
相关问题