Sql 具有多个子查询的配置单元
我试图在where子句中运行多个子查询,得到以下错误。这是否意味着蜂巢不支持它?如果没有,是否有其他方法编写下面的查询 执行配置单元查询时出错:确定失败:SemanticException[错误10249]:第14行不支持的子查询表达式“adh”:仅支持1个子查询表达式Sql 具有多个子查询的配置单元,sql,hive,hiveql,Sql,Hive,Hiveql,我试图在where子句中运行多个子查询,得到以下错误。这是否意味着蜂巢不支持它?如果没有,是否有其他方法编写下面的查询 执行配置单元查询时出错:确定失败:SemanticException[错误10249]:第14行不支持的子查询表达式“adh”:仅支持1个子查询表达式 select first_name, last_name, salary, title, department from employee_t1 emp where
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';
两种选择。一个是joins,另一个是union all:
通常不建议这样做,因为优化选项较少。但是如果配置单元有这个限制,并且我还没有在配置单元中尝试过这种类型的查询,那么这可能是一种解决方法
如果两个表中的comp字段是唯一的,那么join方法最合适。否则,您需要删除重复项以避免联接中的重复。我同意Gordon的观点。使用连接,您可以尝试以下querynot tested:
select
a.first_name,
a.last_name,
a.salary,
a.title,
a.department
from
(Select * from employee_t1 where
emp.salary <= 100000
and department = 'Pediatrics') a
left outer join (select comp from history_t2 where code_hist <> 10) b
on a.code = b.comp
left outer join (select comp from sector_t3 where code_hist <> 50) c
on a.adh = c.comp
where b.comp is not null
or c.comp is not null
;
只是在这里添加一点注释。错误消息表示配置单元仅支持1个子查询。这实际上与配置单元的限制有关:单个查询只支持一个子查询表达式 你可以参考这里的官方文件。 这正是左半联接的用途: 选择 独特的主* 从…起 选择 皇帝的名字, 皇帝姓, emp.salary, 皇帝头衔, 环境管理部 从…起 雇员管理计划 左半连接 从历史记录中选择不同的comp,其中emp代码上的代码历史记录为10 emp代码。comp=emp.code 哪里
emp.salary。但是,不确定是否有多个。在子查询中,应该是select distinct COMP,假设有一行同时满足code和adh条件。使用union时,该行将显示两次,但在问题的原始查询中,该行仅显示一次。使用union将有助于删除重复项。若employee_t1表有重复项,union和union all都将失败,distinct main.*将错误地删除这些重复项。
select
a.first_name,
a.last_name,
a.salary,
a.title,
a.department
from
(Select * from employee_t1 where
emp.salary <= 100000
and department = 'Pediatrics') a
left outer join (select comp from history_t2 where code_hist <> 10) b
on a.code = b.comp
left outer join (select comp from sector_t3 where code_hist <> 50) c
on a.adh = c.comp
where b.comp is not null
or c.comp is not null
;