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