hive:selectas和groupby

vhmi4jdf  于 2021-06-03  发布在  Hadoop
关注(0)|答案(2)|浏览(358)

我有一个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无效的表别名或列引用
“loggertable”是一个配置单元表,所有列都是字符串类型。
有解决这个问题的方法吗?

p5cysglq

p5cysglq1#

试试这个:

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;
insrf1ej

insrf1ej2#

在hive0.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;

相关问题