【发布时间】:2019-07-31 23:20:46
【问题描述】:
我有 2 个具有相同列的表,并让它们如下内连接,我试图获取内连接中未采用的列。我将在 spark-sql 代码中使用它。
select A.pension, B.pension
from Db1.table1 A, Db2.table2 B
where to_date(A.rdt) = '2019-06-20' and A.state = 'ohio' and A.empno= B.empno;
我尝试过使用 UNION ALL,但花费的时间超过了系统超时,没有添加子句。
select A.pension
from Db1.table1 A left outer join
Db2.table2 B
on A.pension = B.pension
where B.pension is null
UNION ALL
select B.pension
from Db2.table2 A left outer join
Db1.table1 B
on A.pension = B.pension
where A.pension is null;
我也尝试过使用完全外连接,也很花时间,查询没有运行。
select A.pension, B.pension
from Db1.table1 A full outer join
Db2.table2 B
on A.empno = B.empno
where to_date(A.rdt) = '2019-06-20' and A.state = 'ohio' and A.pension = NULL or B.pension = NULL
rdt 在时间戳,养老金 int,empno int,
我们只想要内部连接没有选择的记录,输出必须是一个包含A.pension,B.pension列的表,只有这两列不匹配的记录。
【问题讨论】:
标签: sql join hive apache-spark-sql hql