[英]how to use one hive result as condition in another hive query?
I have a question. 我有个问题。 I have two hive tables, first one has condition.
我有两个蜂巢表,第一个有条件。 need dynamically looking for the condition in sec query.
需要在sec查询中动态查找条件。 for example first query:
例如第一个查询:
select col1, col2 from table1. will return account = 'abc'
in second query, I need to use this as condition for example: 在第二个查询中,我需要将此作为条件,例如:
select * from table2
where account = 'abc'
anybody has some idea? 有人有主意吗? thanks in advance
提前致谢
Apache Hive supports use of a join to combine rows from multiple tables based on a related column. Apache的蜂巢支持使用的加入到行基于相关列多个表结合起来。
In this example, there is an accounts
table and an orders
table. 在此示例中,有一个
accounts
表和一个orders
表。 The query uses a join to find all orders corresponding to each account, filtered to just account1
and account2
. 该查询使用
account2
查找与每个帐户对应的所有订单,仅过滤到account1
和account2
。 The accounts
table is simplified to just one column in this example, which perhaps makes it look unnecessary. 在此示例中,
accounts
表简化为仅一列,这也许使它看起来不必要。 In real-world usage, an accounts table would have multiple columns, but the join syntax remains the same. 在实际使用中,一个accounts表将具有多个列,但是联接语法保持不变。
WITH
accounts AS (
SELECT 'account1' AS account_name UNION ALL
SELECT 'account2' AS account_name UNION ALL
SELECT 'account3' AS account_name
),
orders AS (
SELECT 'account1' AS account_name, 'order1' AS order_name UNION ALL
SELECT 'account1' AS account_name, 'order2' AS order_name UNION ALL
SELECT 'account1' AS account_name, 'order3' AS order_name UNION ALL
SELECT 'account2' AS account_name, 'order4' AS order_name UNION ALL
SELECT 'account2' AS account_name, 'order5' AS order_name UNION ALL
SELECT 'account2' AS account_name, 'order6' AS order_name UNION ALL
SELECT 'account3' AS account_name, 'order7' AS order_name UNION ALL
SELECT 'account3' AS account_name, 'order8' AS order_name UNION ALL
SELECT 'account3' AS account_name, 'order9' AS order_name
)
SELECT
orders.account_name,
orders.order_name
FROM accounts
JOIN orders ON accounts.account_name = orders.account_name
WHERE accounts.account_name IN ('account1', 'account2');
account_name order_name
0 account1 order1
1 account1 order2
2 account1 order3
3 account2 order4
4 account2 order5
5 account2 order6
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.