从配置单元中的子查询获取值 [英] get the value from subquery in hive

查看:58
本文介绍了从配置单元中的子查询获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I was trying to parameterise the value in hive rather than hard coding it in query. Below is the query.

select * from employee where sal >30000

但是,与其使用30000的值作为硬编码,我需要它来自如下所示的同一查询.但是我遇到了问题:

But rather than using 30000 value as hard coded I need that to come from the same query like below. But I am running into issues :

select * from employee where sal > (select max(sal) from employee)

感谢您的帮助.

谢谢

推荐答案

您可以尝试使用这种形式的Hive查询.这将使员工的薪水等于最高薪水.

You can try using this form of Hive query. This will get the employees having salary equal to the highest salary.

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

这篇关于从配置单元中的子查询获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆