HIVE:GROUP BY键出错

时间:2015-04-03 00:36:11

标签: sql hadoop hive

hive -e "select a.EMP_ID,
       count(distinct c.SERIAL_NBR) as NUM_CURRENT_EMP,
       count(distinct c.SERIAL_NBR)/count(distinct a.SERIAL_NBR) as DISTINCT_EMP
from   ORDERS_COMBINED_EMPLOYEES as a
inner  join ORDERS_EMPLOYEE_STATS as b
         on a.CPP_ID = b.CPP_ID
left   join (   select SERIAL_NBR, MIN(TRAN_DT) as TRAN_DT
                from   EMP_TXNS
                group  by SERIAL_NBR
            ) c
         on c.SERIAL_NBR = a.SERIAL_NBR
where    c.TRAN_DT > a.LAST_TXN_DT
group by a.EMP_ID
having ( 
          (NUM_CURRENT_EMP >= 25 and DISTINCT_EMP > 0.01)
       ) ; " > EMPLOYEE_ORDERS.txt

收到错误消息,
 "FAILED: SemanticException [Error 10025]: Line 15:31 Expression not in GROUP BY key '0.01'".
当我在HAVING子句中仅使用NUM_CURRENT_EMP >= 25子句中的一个条件运行相同的查询时,查询运行正常,没有任何问题。 NUM_CURRENT_EMP类型为int类型,DISTINCT_EMPfloat,表格中我正在尝试插入结果。打破我的脑袋 任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

如果用having中的别名替换定义它们的表达式,会发生什么?

having count(distinct c.SERIAL_NBR) >= 25 and
       count(distinct c.SERIAL_NBR)/count(distinct a.SERIAL_NBR) > 0.01