Impala SQL嵌套查询语法错误求助:WHERE子句报错解析
Hey there, let's break down why you're hitting that AnalysisException syntax error in Impala.
错误核心原因
The key issue here is a missing alias for your subquery. Impala (along with most SQL dialects that strictly follow SQL standards) requires that any subquery used as a data source in the FROM clause must have an alias assigned to it. When you write FROM (SELECT * FROM spyprice), the query parser doesn't have a valid name to reference this derived result set, so it throws an error—expecting an identifier (the alias) instead of the WHERE clause that follows.
修正后的SQL示例
Just add a simple alias (like t, sub, or any name you prefer) to the subquery, and your query will run correctly:
SELECT currentdate, close FROM (SELECT * FROM spyprice) t WHERE currentdate BETWEEN '2015-01-16' AND '2016-06-17';
补充说明
Even if you don't explicitly use the alias elsewhere in the query, Impala still enforces this rule to ensure the query structure is valid. It's a standard SQL requirement for derived tables, so keeping this detail in mind will help you avoid similar syntax errors in future queries.
内容的提问来源于stack exchange,提问作者James Xiang

