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');
1条答案
按热度按时间gj3fmq9x1#
apachehive支持使用join根据相关列合并多个表中的行。
在这个例子中,有一个
accounts
table和tableorders
table。该查询使用一个联接来查找与每个帐户对应的所有订单,并将其过滤为account1
以及account2
. 这个accounts
在本例中,表被简化为只有一列,这可能使它看起来不必要。在实际使用中,accounts表将有多个列,但联接语法保持不变。查询
结果