Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hive 从配置单元中的子查询获取值_Hive_Hiveql - Fatal编程技术网

Hive 从配置单元中的子查询获取值

Hive 从配置单元中的子查询获取值,hive,hiveql,Hive,Hiveql,我试图在配置单元中对值进行参数化,而不是在查询中对其进行硬编码。下面是查询 select * from employee where sal >30000 但是,我不需要使用30000值作为硬编码,而是需要来自下面相同的查询。但我遇到了一些问题: select * from employee where sal > (select max(sal) from employee) 感谢您的帮助 谢谢您可以尝试使用这种形式的配置单元查询。这将使员工的工资等于最高工资 SELECT e

我试图在配置单元中对值进行参数化,而不是在查询中对其进行硬编码。下面是查询

select * from employee where sal >30000
但是,我不需要使用30000值作为硬编码,而是需要来自下面相同的查询。但我遇到了一些问题:

select * from employee where sal > (select max(sal) from employee)
感谢您的帮助


谢谢

您可以尝试使用这种形式的配置单元查询。这将使员工的工资等于最高工资

SELECT e1.* FROM employee e1 
JOIN
(SELECT MAX(sal) as max_sal FROM employee) e2
ON e1.sal = e2.max_sal;
例如:

Table: employee
id  fname   sal
1   AAA     15000
2   BBB     35000
3   CCC     12000
4   DDD     35000
5   EEE     9000
查询执行输出:

2   BBB     35000
4   DDD     35000

配置单元不支持此类子查询,也不允许计算变量,配置单元中的变量是简单的文本替换,无需计算。您可以在shell中计算谓词,并将其传递给配置单元脚本,如下所示:

如果您想在同一个配置单元查询中执行此操作,那么在计算子查询并对其结果进行交叉连接时不会出错,然后进行筛选。首先计算子查询,然后将其结果放置在分布式缓存中,并应用于读取表的每个映射器的过滤器中:

with sub as(--this is example only and makes no sense
            --replace with real query
            --of course there is no rows with sal>max sal in the same table
select max(S.sal) AS MaxSal from employee S  
)

select * 
  from employee e 
       cross join sub s  
where e.sal>s.MaxSal 

如果您编写它时没有交叉连接,只是从员工e、sub s或JOIN而没有条件,那么它仍然是相同的交叉连接

问题是,接收到任何错误或未返回任何数据?接收到错误作为其不受支持请尝试使用表别名从employee E中选择E.*,其中E.sal>选择maxS.sal作为employee SThanks中的MaxSal,但给出错误:无法识别select near