一种方法是将a
扩大为每天都有一行。
另一种方法是使用交错技术。这假设a
确实划分时间,所以没有重叠或间隙。而且,b
有一个主键。
所以,在b
每个id
就可以得到相应的起始时间a
:
select id, time, a.starttime, a.endtime
from (select id, time, max(starttime) over (order by time, priority) as a_starttime
from ((select b.id, b.time, null as starttime, 2j as priority from b) union all
(select null, a.starttime, a.starttime, 1 as priority from a)
) ab
) ab join
a
on ab.a_starttime = a.starttime;
注:该技术工作
select id, time, max(starttime) over (order by time, priority) as a_starttime
from ((select b.id, b.time, null as starttime, 2j as priority from b) union all
(select null, a.starttime, a.starttime, 1 as priority from a)
) ab;
然后你就可以用等值连接使用以及其他数据库。我没有机会在Hive上试用它。
谢谢你的回复!实际上,在两张表中有很多字段,使用交错技术看起来很麻烦和不方便,是不是?这种情况有另一种方法吗? – Guo
@郭。 。 。不是我可以在Hive中想到的。 –