我很难编写HiveQL Join

时间:2018-09-06 05:48:58

标签: sql join hive hiveql

我很确定已经问过这个问题,但是无法获得我的搜索查询来返回答案。我有两个桌子

artisan migrate:refresh

2 个答案:

答案 0 :(得分:2)

您可以使用var ids = [ObjectId('5ae6d812e5504726a69fc285'),ObjectId('5b0bcfc254c93a2734d56efb')]; 进行此操作:

full join

使用select coalesce(onl.col1, ofl.col1) as col1, coalesce(onl.col2, ofl.col2) as col2, onl.score, ofl.score from (select onl.* from online onl where onl.col1 = 'a' ) onl full join (select ofl.* from offline ofl where ofl.col1 = 'a' ) ofl on onl.col1 = ofl.col1 and onl.col2 = ofl.col2; 进行过滤非常棘手,这就是为什么它使用子查询的原因。

答案 1 :(得分:0)

使用以下查询!

SELECT online.col1
    ,online.col2
    ,coalesce(online.score, 0) AS onlinescore
    ,coalesce(offlilne.score, 0) AS offlinescore
FROM online
INNER JOIN offline
    ON online.col1 = offline.col1
    AND online.col2 = offline.col2
UNION ALL
SELECT online.col1
    ,online.col2
    ,coalesce(online.score, 0) AS onlinescore
    ,'' AS offlinescore
FROM online
LEFT JOIN offline
    ON online.col1 = offline.col1
    AND online.col2 = offline.col2
WHERE offline.col1 IS NULL
UNION ALL
SELECT offline.col1
    ,offline.col2
    ,'' AS onlinescore
    ,coalesce(offline.score, 0) AS offlinescore
FROM offline
LEFT JOIN online
    ON online.col1 = offline.col1
    AND online.col2 = offline.col2
WHERE online.col1 IS NULL