9

我有一个 Hive 查询

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;

上述查询因错误而失败

失败:语义分析错误:第 1:175 行无效的表别名或列引用 secondMod

'LoggerTable' 是一个 Hive 表,其中包含所有字符串类型的列。

这个问题的任何解决方法?

4

2 回答 2

12

试试这个:

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;
于 2012-09-26T11:25:21.420 回答
4

hive.groupby.orderby.position.alias在 Hive 0.11.0 及更高版本中,如果设置为,则可以按位置指定列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;
于 2016-07-28T10:12:02.340 回答