在hive中从横向视图转换为案例陈述。

问题描述 投票:0回答:1

我需要将以下代码放入 案子 声明。

select
count (*)
from db.tab1
lateral view explode(secondary.tertiary) exp as lv
where id IN ('6','1') and array_contains (lv.ci, "1");

我已经试过了

select 
  sum(
    case 
      when id IN ('6','1') 
          and array_contains ((lateral view explode(secondary.tertiary)).ci, "1") 
      then 1 
      else 0 
   end) 
from db.tab1;

但得到错误。

sql hadoop hive hiveql
1个回答
0
投票
select
  count(*),
  sum(if(..., 1, 0))
from db.tab1
  lateral view explode(secondary.tertiary) exp as lv
;

对于提供的SQL表 tab1,实际逻辑是这样的。

  1. 爆炸场 secondary.tertiary,别名为 lv,结果是一个临时的结果集(表) tab2;
  2. 一个类似连接的操作来连接 tab2的字段回到 tab1导致另一个中间表 tab3;
  3. 选择 tab3据此 where 条件是适用于。
© www.soinside.com 2019 - 2024. All rights reserved.