这个查询有什么问题(在配置单元中运行):
SELECT count(*) TotalCount, b.region_code
from XXX a
INNER JOIN YYY b
ON a.uid=b.uid
where a.dt = '2015-04-15'
group by b.region_code order by b.region_code
我认为这应该很简单,但我明白了:
FAILED: SemanticException [Error 10004]: Line 6:32 Invalid table alias or column reference 'b': (possible column names are: _col0, _col1)
这是 YYY 表:
hive> desc YYY;
OK
status_code int
uid string
zip_code string
keyword string
region_code bigint
dt timestamp
channel int
和 XXX 表:
hive> desc XXX;
OK
group_key string
category string
uid string
dt timestamp
尝试这样做:
SELECT count(*) as TotalCount, b.region_code
from XXX a INNER JOIN
YYY b
ON a.ui = b.uid
where a.dt = '2015-04-15'
group by b.region_code
order by region_code
你的代码的问题是b.region_code
之后不存在order by
. The alias存在(region_code
)因为那是在select
. The 合格的别名不,因为b
后不再有效group by
。我想你可以写:
order by max(b.region_code)
但在这种情况下,这是愚蠢的。
请注意,这对于除 MySQL 之外的所有数据库都是通用的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)