简体   繁体   English

在多个字段上进行完全外部联接

[英]Full outer join on multiple fields

I have several tables of academic journal rankings, from different sources and with different citation metrics. 我有几张学术期刊排名的表格,它们来自不同的来源和引用的指标。 I want to combine them in a single table, aggregating data by journal. 我想将它们合并到一个表中,按日记汇总数据。

For example, the first table has columns: 例如,第一个表具有以下列:

ISSN1 ISSN2 Journal_Name_1 Impact_Factor

and the second table has columns 第二个表有列

ISSN3 ISSN4 ISSN5 Journal_Name_2 Citations

Journal names vary between data sources, and any journal may have 0 or more ISSN numbers. 日记名称在数据源之间有所不同,并且任何日记可能具有0个或多个ISSN号。 What I would like to do is creating a new table with columns 我想做的是用列创建一个新表

ISSN1 ISSN2 ISSN3 ISSN4 ISSN5 Journal_name_1 Journal_Name_2 Impact_factor Citations

that includes all journals listed in table 1 or table 2 by merging a row from the first table with one from the second table if the condition 通过合并第一个表中的一行与第二个表中的一个合并来包含表1或表2中列出的所有日记帐

( Journal_Name_1 = Journal_Name_2 ) OR ( at least one of ISSN1 or ISSN2 is equal to at least one of ISSN3, ISSN4, ISSN5)

What is the most effective way to create that result? 产生结果的最有效方法是什么?

(The data is in CSV files at the moment, I could use sqlite/mysql/postgresql/any other DBMS) (目前数据在CSV文件中,我可以使用sqlite / mysql / postgresql /任何其他DBMS)

SQL Fiddle for playing. SQL小提琴演奏。

select t1.*, t2.*
from t1
left join t2 on (journal_name1 = journal_name2)
                or (issn1 in (issn3, issn4, issn5))
                or (issn2 in (issn3, issn4, issn5))
union all
select t1.*, t2.*
from t1
right join t2 on (journal_name1 = journal_name2)
                 or (issn1 in (issn3, issn4, issn5))
                 or (issn2 in (issn3, issn4, issn5));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM