蜂巢:SELECT AS和GROUP BY

问题描述:

我有一个蜂房查询像蜂巢:SELECT AS和GROUP BY

SELECT Year, Month, Day, Hours, Minutes, 
      cast((cast(Seconds as int)/15) as int)*15 
AS secondMod, Count(*) AS PerCount FROM LoggerTable 
GROUP BY Year, Month, Day, Hours, Minutes, secondMod 
ORDER BY PerCount; 

上述查询失败,错误

FAILED: Error in semantic analysis: line 1:175 Invalid Table Alias or Column Reference secondMod

“LoggerTable”是一个蜂巢表与字符串类型的所有列。

任何办法解决这个问题?

尝试这种情况:

SELECT Year, Month, Day, Hours, Minutes, 
cast((cast(Seconds as int)/15) as int)*15 
AS secondMod, Count(*) AS PerCount FROM LoggerTable 
GROUP BY Year, Month, Day, Hours, Minutes, 
    cast((cast(Seconds as int)/15) as int)*15 
ORDER BY PerCount; 
+0

这是一个巨大的痛苦,如果你要定义一个非常复杂的'SELECT'并希望在你的'WHERE','GROUP BY'和'ORDER BY'使用它。这里有http://stackoverflow.com/questions/26028767/why-cant-hive-recognize-alias-named-in-select-part一种变通方法 – ubershmekel

在蜂房0.11.0和以后,列可以由位置指定如果hive.groupby.orderby.position.alias设置为true。 请确认以下查询是否适合您。

SET hive.groupby.orderby.position.alias=true; 
SELECT Year 
     ,Month 
     ,Day 
     ,Hours 
     ,Minutes 
     ,cast((cast(Seconds as int)/15) as int)*15 AS secondMod 
     ,count(*) AS PerCount 
FROM LoggerTable 
GROUP BY 1, 2, 3, 4, 5, 6 
ORDER BY 7; 
+0

我想这有点的,但它也只会对工作组。当我尝试命令时,查询失败。你有什么想法为什么会发生?我的查询如下所示: 'SET hive.groupby.orderby.position.alias = true; SELECT device,COUNT(DISTINCT from_user)AS users_sharing FROM

GROUP BY 1顺序通过2 DESC LIMIT 10' 我得到了以下错误: 'FAILED:SemanticException [错误10004]:行4:21无效表别名或列引用 'FROM_USER':(可能的列名称是:设备,users_sharing)' –
+0

抱歉的格式。我无法弄清楚如何发布保存了缩进的查询。 –

+0

确认您的'from_user'表别名或列引用存在。也许不同的拼写,错字。一个可能的解决方案是将您的查询分为两部分: 'hive.groupby.orderby.position.alias = true; SELECT res.device,res.users_sharing FROM(SELECT装置,COUNT(DISTINCT FROM_USER)AS users_sharing \t FROM

\t GROUP BY 1 \t极限10; \t)AS水库 ORDER BY res.users_sharing' 让我们知道你是如何解决你的问题的! – rafaelvalle

相关推荐