根据基于蜂巢中另一个表中的值限制在表上的行中的行

  • 本文关键字:另一个 于蜂巢 蜂巢 hive
  • 更新时间 :
  • 英文 :


我先尝试了。

Create table tablec (
 id string,
 group int,
 rownumber int);
insert into table c 
select * from (select distinct a.id,a.group,a.rownumber from 
table a join table b 
on a.group = b.group where a.rownumber <= b.rownumber ) T;

我也尝试了以下查询并获得相同的结果。

insert into table c 
select * from (select a.id, a.group, a.rownumber from 
table a , table b 
where a.group = b.group and a.rownumber <= b.rownumber ) T;

运行查询时我不会遇到错误。它正在创建表C,但值不限。谁能暗示我为什么会发生?

示例屏幕截图

我认为您不必使用JOINDISTINCT。这样的相关exists查询应该很好。首先,查看它是否仅给您所需的记录。然后使用此选择。

运行您的Insert语句。
SELECT a.group_id
    ,a.group_name
    ,a.rownumber
FROM tablea a
WHERE EXISTS (
        SELECT 1
        FROM tableb b
        WHERE a.group_id = b.group_id
            AND a.rownumber <= b.rownumber
        );

demo

最新更新