HIVE中的WITH子句

时间:2017-08-25 01:41:51

标签: hive

在下面的代码 temp1 中使用了2次,那么hive会在temp1中执行select查询两次吗?或只是一次?

with temp1(
select distinct b as b, f, t1.id as id,       
from
   table1 t1
join 
   table2 t2 on (t1.id=t2.id)
),
agg_tbl as 
(
 select
     max(abc) as maxabc,
     tbl.t
 from(
   select
        count(*) as cnt,  b, f
  from
       temp1
  group by
       b, f
  ) tbl group by tbl.t
), 
class_tbl as
(select
      case 
         when bp = 1 then 'abc'
         when bp = 2 then 'xyz'
     end as class,
    bp
 from
 ( select
       count(b) as bcount, bp
    from
       temp1
   group by  bp
 )tbl
)

如果是这种情况,那么使用临时表是有意义的。

感谢。

0 个答案:

没有答案