我对Hive比较陌生。探索合并两个不通过键连接的表的方法。因此,我没有在查询中使用“ON”条件。
下面是table_1:
COL1
hello
下面是table_2:
COL2
world
excellent
预期结果 :
hello world
NULL excellent
实际结果 :
hello world
hello excellent
我的查询:
select col_one,
col_two
from (
select COL1 as col_one
from table_1
) as c1
join (
select COL2 as col_two
from table_2
) as c2;
我不确定table_1中没有第2行时结果中的“hello”如何出现
最佳答案
我不确定没有on
子句的查询的工作方式。但是,您可以使用row_number()
来完成所需的操作,如下所示:
select c1.col_one, c2.col_two
from (select COL1 as col_one, row_number() over (order by col1) as seqnum
from table_1
) c1 join
(select COL2 as col_two, row_number() over (order by col2) as seqnum
from table_2
) c2
on c1.seqnum = c2.seqnum;
关于sql - HIVE JOIN两个具有不同行数的表给出错误的列值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45908599/