通过使用hive将两个表连接到c中来存储最新的tweet

0sgqnhkj  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(303)

我有3个表a,b,它们的共同点是tweeetid,account\ id,在这两个表中我想连接a和b,因为我有一个查询

Select created_date, tweet_text, user_description
from A inner join
     B
     on A.tweetId = B.tweetId and A.account_id = B.accountid;

我想在加入b之后取最新的创建日期,然后将最新的创建日期与c的最新创建日期进行比较。因此,目标是每次查询运行时,我都需要在a中存在最新tweet的情况下将数据插入c,而b必须转储到c中。

gpnt7bae

gpnt7bae1#

要按日期获取最新tweet,请使用row\ u number()函数。这样地:

insert overwrite C  --or insert into
select * from 
(
    select created_date, tweet_text, user_description
           row_number() over(partition by weetId, account_id order by created_date desc) as rn,
           tweetId, account_id --PK 
    from A inner join
         B
         on A.tweetId = B.tweetId and A.account_id = B.accountid
)s
where s.rn=1; --take the latest

相关问题