Invalid table alias or column reference b

匿名 (未验证) 提交于 2019-12-03 00:48:01

问题:

What's wrong with this query (running in hive):

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 

I think it should be pretty straightforward, but am getting this:

FAILED: SemanticException [Error 10004]: Line 6:32 Invalid table alias or column reference 'b': (possible column names are: _col0, _col1) 

Here is the YYY table:

hive> desc YYY; OK status_code     int uid    string zip_code        string keyword string region_code     bigint dt      timestamp channel int 

and XXX table:

hive> desc XXX; OK group_key     string category    string uid    string dt      timestamp 

回答1:

Try doing this:

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 

The problem with your code is that b.region_code doesn't exist after the order by. The alias exists (region_code) because that is in the select. The qualified alias does not, because the b is no longer valid after the group by. I think you could write:

order by max(b.region_code) 

But that would be silly in this case.

Note that this is common to all databases, except MySQL.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!