【问题标题】:Include sub query result in select statement in hive在 hive 的 select 语句中包含子查询结果
【发布时间】:2021-06-25 15:54:41
【问题描述】:

我希望子查询结果成为主查询的一部分,这在 hive 中是否可行

select distinct table1.col1,table1.col2,
calcolumn= 
(select count(table1.newcal) 
                     from   Table 1 table2
                     where  table2.col1 = table1.col1
                            and table2.col2 = table1.col2)
                  from Table 1 table1

我看到如下错误

编译语句时出错:FAILED: ParseException line 3:1 无法识别表达式中“(”“选择”“计数”附近的输入 规格

【问题讨论】:

    标签: sql hive hiveql


    【解决方案1】:

    使用类似这样的显式连接:

    select t1.col1,t1.col2, 
           count(distinct case when t2.col1 is not null then t1.newcal else null end) as calcolumn
       from Table 1 t1
            left join table2 t2 on t2.col1 = t1.col1 and  t2.col2 = t1.col2
    group by t1.col1,t1.col2
    

    【讨论】:

      最近更新 更多