比较配置单元中具有相同结构的两个表之间的数据 [英] compare data between two tables with same structure in hive

查看:45
本文介绍了比较配置单元中具有相同结构的两个表之间的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何比较hive中具有相同结构的两个表.我相信减号在蜂巢中不起作用.

How to compare two tables with same structures in hive. I believe minus will not work in hive.

SRC 表:

id name
1   A
2   B
3   C

TGT 表:

身份证名称

1   A
2   C
3   C

谁能帮我查询.

推荐答案

如果您正在寻找两个表之间的相等性和差异(如果有),您可以按照以下操作

SELECT MIN(TableName) as TableName, ID, NAME从(SELECT 'SRC_TABLE' 作为表名、A.ID、A.NAME从 A联合所有SELECT 'TGT_TABLE' 作为表名、B.ID、B.NAME从 B) 时间按 ID、名称分组有计数(*) = 1按 ID 订购

上面的查询基本上是这样的,

Basically what the above query does is as follows,

  • 合并两个表中的所有记录 &按所有列对它们进行分组.稍后仅打印出那些唯一的记录 [具有 count(*) = 1].

如果上述查询打印零记录,则表示两个表完全相等

If the above query prints zero records then it means both the tables are perfectly equal

对于上面列出的示例,输出如下,

For the above example you listed the output is as follows,

<代码>[ TBL_NAME |身份证 |姓名]

----------------------------

<代码>[ SRC_TABLE |2 |B ]

<代码>[ TGT_TABLE |2 |C ]

致谢:我从这个 网站.我试过了,太棒了!

Credits: I found the above solution from this website. I tried it, and it was fantastic!

这篇关于比较配置单元中具有相同结构的两个表之间的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆