简体   繁体   English

比较两个表并获得具有各自列名的不匹配数据的输出

[英]Compare two tables and get output with unmatched data with respective column name

I have two tables similar to following construct.我有两个类似于以下构造的表。 I need to compare both and get the output as shown in results.我需要比较两者并获得如结果所示的输出。

Here I am comparing column1 with column4, column2 with column5 and column3 and column6.在这里,我将 column1 与 column4、column2 与 column5 以及 column3 和 column6 进行比较。

Table1:表格1:

Key column1 column2 column3
1    4       5       6
2    2       5       8
3    4       5       10
4    4       6       10

Table2:表2:

Key column4 column5 column6
1    6       5       6
2    2       5       8
3    4       5       10
4    4       8       10

Result should be:结果应该是:

Key1 Table2ColumnName Table1ColumnValue Table2ColumnValue
1    column4              4                  6
4    column5              6                  8    

Note : In actual case, I have tables with huge number of columns to compare.注意:在实际情况下,我有大量要比较的列的表。 Column names in both table are different.两个表中的列名不同。

Could someone kindly guide on how to achieve the above requirement.有人可以指导如何实现上述要求。

I don't think this will be solved with a SQL query since you want to do this dynamically and there isn't a consistent naming for the columns.我认为这不会通过 SQL 查询解决,因为您想动态地执行此操作,并且列没有一致的命名。 The example you gave is short and sweet but you mentioned you have 'tables with huge number of columns to compare'.你给出的例子简短而甜蜜,但你提到你有“有大量列要比较的表”。

You might be better off importing each table you want to compare into an Excel spreadsheet (one table per sheet) and doing some VLOOKUP formulas.您最好将要比较的每个表格导入 Excel 电子表格(每张表格一个表格)并执行一些 VLOOKUP 公式。

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

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