配置单元:具有单个子查询的多个in元素

zour9fqk  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(374)

我试图在hive(版本1.2.1)上运行这样的查询:

DELETE  FROM employee as e WHERE  (e.id, e.name) IN ( SELECT emp.id, emp.name FROM employee_final  emp) AND e.sno = 120 ;

但由于Hive不支持这种结构,所以我尝试了:

DELETE FROM employee WHERE 
id  IN (  SELECT emp.id  FROM employee_final AS  emp ) 
AND 
name IN ( SELECT emp.name  FROM employee_final AS  emp      )  
AND e.sno = 120 ;

但似乎有一个限制,在配置单元,它只支持1个子查询,我得到这样一个例外
错误消息:语法错误的sql查询:];嵌套异常为org.apache.hive.service.cli.hivesqlexception:编译语句时出错:失败:semanticexception[error 10249]:行1:185不支持的子查询表达式“name”:仅支持1个子查询表达式。
处理这个问题最有效的方法是什么。

xxe27gdn

xxe27gdn1#

你可以试着跟着
通过exists,我不确定hive是否支持此子查询表单。

DELETE FROM employee as e WHERE EXISTS ( SELECT 1 FROM employee_final emp where e.id = emp.id and e.name =  emp.name ) AND e.sno = 120 ;

通过concat函数

DELETE FROM employee as e WHERE concat (e.id, '#' ,e.name) IN ( SELECT concat (emp.id,'#' ,emp.name) FROM employee_final emp) AND e.sno = 120 ;

相关问题