如何在配置单元中的select语句中编写子查询

时间:2014-12-22 08:59:58

标签: hadoop hive

我正在尝试使用配置单元进行子查询选择。

在foos表中有以下列:

foo1,
foo2,
foo3_input

是我想要的

select foo1, foo2, foo3 from foos;

我将执行

select foo1, foo2, foo3_input from foos;

对于连续的每个foo3我想执行以下查询

foo3 = select bar1 from bars where (foo3_input) between val1 and val2;

有没有办法构建这个查询?

3 个答案:

答案 0 :(得分:3)

select
    a.foo1, 
    a.foo2,
    b.bar1
from
(
    (select foo1, foo2, foo3_input from foos) a
    left outer join
    (select bar1, foo3_input from bars ) b
    on a.foo3_input = b.foo3_input
 )tmp
 where b.foo3_input between a.foo1, a.foo2
 ;

[编辑]

select
    a.foo1, 
    a.foo2,
    b.bar1
from
(
    (select foo1, foo2, foo3_input from foos) a
    full outer join
    (select bar1, val1, var2 from bars ) b

 )tmp
 where a.foo3_input between b.val1, b.val2
 ;

答案 1 :(得分:1)

“Hive不支持WHERE子句中的IN,EXISTS或子查询。” 见https://issues.apache.org/jira/browse/HIVE-1799

请参阅hive https://cwiki.apache.org/confluence/display/Hive/LanguageManual+SubQueries#LanguageManualSubQueries-SubqueriesintheWHEREClause

中的where子句

答案 2 :(得分:0)

Hive版本0.13.0

select
    a.foo1, 
    a.foo2,
    b.bar1
from foos a, bars b
where a.foo3_input between b.val1, b.val2;