我有下面的数据,我想获取每个ID的最新分区时间
我期望的输出如下
15 10038446 201706060100
19 10103517 201706060100
26 10124464 201706060100
37 1019933 201706052100
如何使用Hive查询来实现?
最佳答案
试试这个
select ID, time
from
(
select
ID,
time,
row_number() over (partition by ID order by time desc) as time_rank
from table_name
) x
where time_rank = 1
group by ID, time
如果没有子查询(较低的配置单元版本),则临时表是一种选择。
create table tmp_table as
select
ID,
time,
row_number() over (partition by ID order by time desc) as time_rank
from table_name;
select ID, time
from tmp_table
where time_rank = 1
group by ID, time;
drop table tmp_table;
关于hadoop - 查询以查找最大值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45499961/