我试图在 where 子句中运行多个子查询,但出现以下错误。是否意味着 Hive 不支持它?如果没有,是否有其他方法来编写下面的查询?
执行配置单元查询时发生错误:确定失败:SemanticException [错误 10249]:第 14 行不支持的子查询表达式“adh”:仅支持 1 个子查询表达式。
select
first_name,
last_name,
salary,
title,
department
from
employee_t1 emp
where
emp.salary <= 100000
and (
(emp.code in (select comp from history_t2 where code_hist <> 10))
or
(emp.adh in (select comp from sector_t3 where code_hist <> 50))
)
and department = 'Pediatrics';
Run Code Online (Sandbox Code Playgroud)
两个选择。一个是joins,另一个是union all:
where emp.salary <= 100000 and
emp.code in (select comp
from history_t2
where code_hist <> 10
union all
select comp
from sector_t3
where code_hist <> 50
) and
emp.department = 'Pediatrics';
Run Code Online (Sandbox Code Playgroud)
通常不建议这样做,因为优化选项较少。但是如果 Hive 有这个限制(并且我还没有在 Hive 中尝试过这种类型的查询),那么这可能是解决它的一种方法。
如果两个表中的字段是唯一的,则该join方法将是最合适的。comp否则,您需要删除重复项以避免join.