如何检查HIVE中有条款的顺序排序?

时间:2016-08-16 19:10:27

标签: sql hadoop hive

我希望能够编写一个查询,告诉我哪些数据组没有序列中的每个数字。

例如,我的表就像这样:

Columns:   sequence  group1
           0         ADM
           1         ADM
           0         GDM
           2         GDM
           3         GDM
           0         WJK

并且,我想知道group1中哪些唯一值包含从0开始计算的所有数字。因此,在这种情况下,ADMWJK会被返回,但GDM则不会。 GDM不会,因为它从0,2,3开始跳过1.

如何在HIVE中编写查询,告诉我group1列中的哪些唯一值按顺序包含所有整数?

3 个答案:

答案 0 :(得分:1)

由于序列开始形成零

,因此可以使用count和max
 select group1
 from my_table 
 group by group1
 having count(*) = max(sequence) +1

您的最后评论然后您可以使用

 select group1
 from my_table 
 group by group1
 having count(distinct sequence) = max(sequence) +1

答案 1 :(得分:1)

returnAPromise('third').then($scope.messages.push.bind($scope.messages));

如果基于0或正整数

,则有效

答案 2 :(得分:0)

如果sequence可能有重复项,那么您需要小心。一种方法是采用一个真实的序列,减去它,并确保差异是不同的:

select group1
from (select t.*,
             (sequence - row_number() over (partition by group1 order by sequence)) as diff
      from t
     ) t
group by group1
having min(diff) = max(diff);