使用HiveQL进行重复数据删除

时间:2013-04-16 12:17:50

标签: hive hiveql deduplication

我有一个带有字段'a'(int),'b'(字符串),'c'(bigint),'d'(bigint)和'e'(字符串)的hive表。
我有以下数据:

a  b  c   d   e
---------------
1  a  10  18  i
2  b  11  19  j
3  c  12  20  k
4  d  13  21  l
1  e  14  22  m
4  f  15  23  n
2  g  16  24  o
3  h  17  25  p

表格按键'b'排序。
现在我们想要输出如下:

a  b  c   d   e
---------------
1  e  14  22  m
4  f  15  23  n
2  g  16  24  o
3  h  17  25  p

将在关键字'a'上扣除,但会保留最后(最新)'b'。

是否可以使用Hive查询(HiveQL)?

1 个答案:

答案 0 :(得分:1)

如果列b是唯一的,请尝试按照hql:

select 
* 
from
(
    select max(b) as max_b
    from
    table
    group by a
) table1
join table on table1.max_b = table.b