我试图在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 ;
但似乎hive有一个限制,它只支持1个子查询,我得到一个像这样的例外
错误消息:语法错误的SQL查询:];嵌套 异常是org.apache.hive.service.cli.HiveSQLException:同时出错 编译语句:FAILED:SemanticException [错误10249]:行 1:185不支持的SubQuery Expression'name':只有1个SubQuery 支持表达式。
解决此问题的最有效方法是什么。
答案 0 :(得分:0)
您可以尝试以下
通过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 ;