我在sas中有一个θ连接,需要翻译成Hive。
sas公司:
select a.id,b.name from employee a
left outer join company b
on ( a.id=b.id and a.joindate>=b.joindate and a.releasedate < b.releasedate)
因为这不是内部连接,所以如果在where条件中添加非equi连接(左表中所有不匹配的记录都丢失),就不会得到正确的结果。
在Hive中试用:
select a.id,b.name from employee a
left outer join company b
on ( a.id=b.id)
where a.joindate>=b.joindate and a.releasedate < b.releasedate
有什么建议吗?
1条答案
按热度按时间u5i3ibmn1#
正如你可能已经意识到的,
left join
保留保留行表(employee)中的所有项,而where
过滤掉那些项目如果a.joindate<b.joindate or a.releasedate >= b.releasedate
.那些
on
条件在逻辑上解释为:对于每个项目
li
从左表中,每当ri
从右表中找到符合on
条件,创建新项ni
其列值是li
以及ri
. 然后把ni
在结果集中。这可能会复制左表中的行。如果
li
找不到匹配项,请复制一个,然后用空值填充正确的列。将此项也放入结果集中。所以我们可以通过以下方式来模拟这种行为:
松开
on
通过在on
条款;过滤掉由系统产生的多余行
on
条件,即不满足相等条件以外的条件的行。结果查询可能如下所示: