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

xxhby3vn  于 2021-05-30  发布在  Hadoop
关注(0)|答案(3)|浏览(400)

我正在尝试使用配置单元对子查询进行选择。
在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;

有没有任何可能的方法来构造这个查询?

k5hmc34c

k5hmc34c1#

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
 ;
pcww981p

pcww981p2#

配置单元版本0.13.0

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

whitzsjs3#

配置单元不支持where子句中的in、exists或子查询 https://issues.apache.org/jira/browse/HIVE-1799 查看此配置单元中的where子句 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+SubQueries#LanguageManualSubQueries-SubqueriesintheWHEREClause

相关问题