hive - 如何从 Hive 中的两个表中获取不匹配的记录?
问题描述
我有以下两个数据表,我只需要使用 hive 获取不匹配的数据记录。
表格1:
hive> select * from dept;
OK
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
表2:
hive> select * from dept_text;
OK
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
50 Software Bangalore
60 Housewife yellandu
输出:我需要得到如下输出。有人可以帮我解决这个问题吗?
50 Software Bangalore
60 Housewife yellandu
解决方案
left join
在dept_text表上使用,然后仅过滤dept表中的空 id列
select dt.* from dept_text dt
left join
dept d
on d.id=dt.id
where d.id is null;
Example:
desc dept;
--id int
--desc string
--city string
select * from dept;
--OK
--dept.id dept.desc dept.city
--10 ACCOUNTING NEW YORK
--20 RESEARCH DALLAS
--30 SALES CHICAGO
--40 OPERATIONS BOSTON
--if you want to join on desc column
select dt.* from dept_text dt
left join
dept d
on d.desc=dt.desc
where d.id is null;
--or if you want to join on id column
select dt.* from dept_text dt
left join
dept d
on d.id=dt.id
where d.id is null;
推荐阅读
- amazon-web-services - 使用 for_each 与资源的 Terraform 相关性
- django - Django 使用表单内的表单验证图像或文件
- node.js - Telegram webhook 集成以表达应用程序
- javascript - 如何在 Material UI 中向 SearchAppBar 添加搜索功能?
- windows - 为 URLMON_OPTION_USERAGENT 调用 UrlMkGetSessionOption 总是返回 E_OUTOFMEMORY
- sql - 在 SQL 中查找最接近的匹配项
- javascript - 寻求有关嵌套 jsx 组件中的 onclick 侦听器的解释
- c# - 使用'is'关键字与'as'关键字性能差异的局部变量声明
- c# - Stream:在一个过程中混合 Write 和 WriteAsync
- environment-variables - 在 google colab 中使用 %cd 或 % run 和环境变量不起作用