Hive Union Group出错

时间:2014-11-06 12:50:20

标签: hadoop hive hiveql

在下面的查询中,我试图计算“primary”列的不同和总出现次数,并对每列进行汇总。

我有两个源表,其中包含类似的信息。在计算之前,我想将这些信息结合起来将所有信息汇总在一起。

但是,使用下面的逻辑我得到以下错误。有人可以告诉我哪里出错了吗?

select COUNT(distinct primary), COUNT(primary), mycolumn 
from  (select primary, mycolumn from mytablea where mycolumn >= a and mycolumn <= b 
     union all 
     select primary, mycolumn from mytableb where mycolumn >= a and mycolumn <= b) 
group by mycolumn

FAILED:ParseException在'group'附近'by'处缺少EOF

谢谢..

1 个答案:

答案 0 :(得分:16)

您必须为子查询提供别名。这样的事情应该有效:

select COUNT(distinct primary), COUNT(primary), mycolumn 
from  (select primary, mycolumn from mytablea where mycolumn >= a and mycolumn <= b 
     union all 
     select primary, mycolumn from mytableb where mycolumn >= a and mycolumn <= b) q1
group by mycolumn