在Excel或OpenOffice中的公共列上加入两个电子表格

Ste*_*rst 28 sql excel openoffice.org openoffice-calc

我有两个带有公共列的CSV文件,我想在公共列上"连接"表.

例如:加入'A'与'B'等于'Result'.如果一个表具有在另一个表中不存在的键值,则其刚刚保留为空白.

== Table A ==        == Table B ==        == Table result ==
Name  ,Age           Name  ,Sex           Name ,Age ,Sex
Bob   ,37     +      Bob   ,Male     =>   Bob  ,37  ,Male
Steve ,12            Steve ,Male          Steve,12  ,Male
Kate  , 7                                 Kate , 7  , 
                     Sara  ,Female        Sara ,    ,Female 
Run Code Online (Sandbox Code Playgroud)

我知道如何使用SQL数据库执行此操作但我从未使用"Excel"或"OpenOffice.org Calc"执行此操作

建议?

rob*_*ert 32

在Excel中,vlookup可以完成您所要求的部分内容.具体来说,您可以使用vlookup执行左外连接或右外连接,但不能使用完整外连接(如表结果).

要为上面的示例执行外连接,请将以下内容添加到"表B"的C2中(或复制"表B",然后执行此操作):

=vlookup(
    a2, # the cell value from the current table to look up in the other table
    table_a!$1:$174832718, # the other table
                           # don't manually type this--select the entire 
                           # other table while the cursor is editing this
                           # cell, then add the "$"s--Excel doesn't
                           # automatically add them
                           # (the syntax here is for different sheets in
                           # the same file, but Excel will fill this in 
                           # correctly for different files as well)
    2, # the column to get from the other table (A=1, B=2, etc.)
    FALSE) # FALSE=only get exact matches TRUE=find approx. matches if no exact match
Run Code Online (Sandbox Code Playgroud)

然后,您应该能够扩展它以处理多行和多个导入的列.


Bee*_*Guy 9

在Excel中,您可以使用VLOOKUP它.
假设您在Excel中的A列和B列中列出了表A中的数据.
表B中的数据列在E和F列中.
现在,转到C列的第一行并输入:

=VLOOKUP(A:A,E:F,2,FALSE) 
Run Code Online (Sandbox Code Playgroud)

这告诉它尝试将列A与列E匹配,并抓住我们找到它的第二列中的任何内容并将其放在列C中.
现在自动填充列C中的其余行以匹配其余数据.