HiveQL使用where not exists子句时出现‘Mismatched input 'select'’错误求助
Hive查询语法错误分析与解决
错误原因
Hive的NOT EXISTS语法要求,其后必须紧跟被括号包裹的子查询。你的查询在NOT EXISTS后直接写select语句,没有用括号将后续子查询整体包裹,导致语法解析器无法识别正确的结构,因此抛出mismatched input 'select'. Expecting: '('错误。
原错误查询
select d1.* from (select dim_iso_code from tableA where ds='2022-06-01') d1 where not exists select d2.* from (select dim_iso_code from tableA where ds='2022-04-18') d2 where d1.dim_iso_code = d2.dim_iso_code
修正后的正确查询
select d1.* from (select dim_iso_code from tableA where ds='2022-06-01') d1 where not exists ( select d2.* from (select dim_iso_code from tableA where ds='2022-04-18') d2 where d1.dim_iso_code = d2.dim_iso_code )
关键修正点
在NOT EXISTS后添加一对括号,将整个用于存在性检查的子查询包裹起来,符合Hive对NOT EXISTS的语法要求:WHERE NOT EXISTS (子查询)。子查询内部的逻辑无需修改,仅需通过括号明确其作为NOT EXISTS的检查对象。
内容的提问来源于stack exchange,提问作者WestCoastProjects
相关产品推荐
相关产品推荐

